Home    Libraries > library:unit > INTRO library:unit
prev next

The unit library allows unit type information to be attached to float values. For example multiplying an velocity meter(100) / second by a time second(4) yields meter(25). The utest example shows more possible forms.

The kinds of units are arbitrary. The INTRO library:stdunit library defines many common one.

Units are checked by keeping track of exponents for each kind of unit. For example velocity (@icode{meter/second}/>) will have non-zero exponents [meter=1,second=-1]. Addition, subtraction, and comparison infix operations require that the exponents of both unit operands be equal.

Unit values can be mixed in arithmetic operations with int and float values. Results with all exponents of zero will have type float.

The following unit multipliers are also defined by this library.

For example a kilometer is written as kilo[meter] and a milligram is written as milli[gram].