Packages

  • package root
    Definition Classes
    root
  • package de
    Definition Classes
    root
  • package h2b
    Definition Classes
    de
  • package scala
    Definition Classes
    h2b
  • package lib
    Definition Classes
    scala
  • package phys
    Definition Classes
    lib
  • package units

    This is a Scala library of units of measurement featuring the International System of Units (SI).

    This is a Scala library of units of measurement featuring the International System of Units (SI).

    Imports

    In most cases, to use this package you will import all of this:

    import de.h2b.scala.lib.phys.units.Quantity
    import de.h2b.scala.lib.phys.units.Quantity._
    import de.h2b.scala.lib.phys.units.base._
    import de.h2b.scala.lib.phys.units.derived._

    Quantities

    A quantity is composed of a magnitude and a unit.

    val m = Quantity(10, kilogram) //> m  : Quantity[MassUnit] = 10.0 kg
    val l = Quantity(0.981, metre) //> l  : Quantity[LengthUnit] = 0.981 m
    val t = Quantity(1, second)    //> t  : Quantity[TimeUnit] = 1.0 s

    You can add or subtract quantities of the same unit and multiply or divide quantities of arbitrary units. Also, you can scale a quantity by a factor.

    val m2 = m + Quantity(20, kilogram) //> m2  : Quantity[MassUnit] = 30.0 kg
    val m3 = 2 * Quantity(1, meter)     //> m3  : Quantity[LengthUnit] = 2.0 m

    Multiplication and division of two quantities need an implicit unit operation that guarantees that the result becomes a quantity of proper unit. The other operations simply yield a quantity of the same unit as the operator.

    val f = m * ((l / t) / t) //> f  : Quantity[ForceUnit] = 9.81 kg*m/s/s

    The system is smart enough to derive that a quantity of units kilogram * ((metre / second) / second) is a quantity of ForceUnit. (Actually however, for now it is not smart enough if the order of operands is changed: ((l / t) / t) * m would not work -- in doubt try it out and inspect the unit objects mentioned below.)

    The quantity class extends the Equals trait and there is also a ~= operator that compares quantities within an implicitly specified tolerance to compensate rounding errors.

    The companion object provides implicit Double operations so that you can write, e.g., 10.m instead of Quantity(10, metre).

    Quantity(10, metre) == 10.m //> Boolean = true

    Units

    Units are based on the *Système international d’unités* (SI -- which gave this package its name), i.e., each unit [Q] can mathematically be expressed in terms of the base units metre, kilogram, second, ampere, kelvin, mol and candela by the equation

    [Q] = ξ·10n·mα·kgβ·sγ·Aδ·Kε·molζ·cdη

    For ξ=1 we have a (potentially derived) SI unit; for ξ=1 and n=0 we have a coherent SI unit.

    The base package provides classes for the seven base units (plus a NeutralUnit) with implicit multiplication and division operations (as mentioned above) and associated objects of common names like metre, kilogram, second and so on.

    The derived package provides the same for a (of course not complete) bunch of derived SI units like squareMetre, newton, pascal, joule, watt or volt.

    The Prefix class has case objects providing the usual SI prefixes like kilo or milli along with a multiplication operation for units.

    You can implement other units by providing the same components for the new unit as the base or derived packages do. For details see there.

    Definition Classes
    phys
  • package base
    Definition Classes
    units
  • package derived
    Definition Classes
    units
  • Prefix
  • Quantity
  • Unit
  • atto
  • centi
  • deca
  • deci
  • exa
  • femto
  • giga
  • hecto
  • kilo
  • mega
  • micro
  • milli
  • nano
  • peta
  • pico
  • tera
  • yocto
  • yotta
  • zepto
  • zetta

object zepto extends Prefix with Product with Serializable

Linear Supertypes
Serializable, Serializable, Product, Equals, Prefix, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. zepto
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Prefix
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def *[U <: Unit[U]](u: Unit[U]): Unit[U]
    Definition Classes
    Prefix
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): scala.Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. val name: String
    Definition Classes
    Prefix
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): scala.Unit
    Definition Classes
    AnyRef
  15. final def notifyAll(): scala.Unit
    Definition Classes
    AnyRef
  16. val symbol: String
    Definition Classes
    Prefix
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. val value: Int
    Definition Classes
    Prefix
  19. final def wait(): scala.Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): scala.Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): scala.Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Prefix

Inherited from AnyRef

Inherited from Any

Ungrouped