# Packages

• package
Definition Classes
root
• package
Definition Classes
root
• package
Definition Classes
de
• package
Definition Classes
h2b
• package
Definition Classes
scala
• package
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
• package
• Prefix
• Quantity
• Unit
• atto
• centi
• deca
• deci
• exa
• femto
• giga
• hecto
• kilo
• mega
• micro
• milli
• nano
• peta
• pico
• tera
• yocto
• yotta
• zepto
• zetta
p

# units 

#### package units

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.

Linear Supertypes
AnyRef, Any
Ordering
1. Alphabetic
2. By Inheritance
Inherited
1. units
2. AnyRef
3. Any
1. Hide All
2. Show All
Visibility
1. Public
2. All

### Type Members

1. sealed abstract class Prefix extends AnyRef

An SI prefix.

2. class Quantity [U <: Unit[_]] extends Equals

A physical quantity composed of a magnitude and a unit.

3. class Unit [U <: Unit[_]] extends Equals

A unit of measure.

A unit of measure.

Decomposition of this unit [Q] into SI base units according to the equation:

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

The exponents are represented by a vector starting with index 0 for `n` etc while `ξ` becomes an own field `scale`.

Two units are considered to be equal if their SI exponents and scale are the same, respectively. The name and symbol strings have no meaning regarding to equality.

For `ξ==1` we have a (potentially derived) SI unit.

For `ξ==1` and `n==0` we have a coherent SI unit.

https://de.wikipedia.org/wiki/Internationales_Einheitensystem

### Value Members

1. object
2. object
3. object atto extends Prefix with Product with Serializable
4. object centi extends Prefix with Product with Serializable
5. object deca extends Prefix with Product with Serializable
6. object deci extends Prefix with Product with Serializable
7. object exa extends Prefix with Product with Serializable
8. object femto extends Prefix with Product with Serializable
9. object giga extends Prefix with Product with Serializable
10. object hecto extends Prefix with Product with Serializable
11. object kilo extends Prefix with Product with Serializable
12. object mega extends Prefix with Product with Serializable
13. object micro extends Prefix with Product with Serializable
14. object milli extends Prefix with Product with Serializable
15. object nano extends Prefix with Product with Serializable
16. object peta extends Prefix with Product with Serializable
17. object pico extends Prefix with Product with Serializable
18. object tera extends Prefix with Product with Serializable
19. object yocto extends Prefix with Product with Serializable
20. object yotta extends Prefix with Product with Serializable
21. object zepto extends Prefix with Product with Serializable
22. object zetta extends Prefix with Product with Serializable