Units of Measure
A unit of measure is a specification that uses numbers to tell you about a physical quantity. You can compare two quantities only if they have the same unit. If they have different units, you must change one to the other. When you change a unit, then you must change the number, usually by multiplication.
For many centuries, different cultures used different units for the same dimensions. Frequently they could not agree how to change between units.
Most cultures currently use the metric system. But Myanmar, Liberia, and the USA reject it. Also, The UK uses it less than other parts of Europe. But also those using the metric system can disagree on how much resolution is necessary, e.g. 1.5 seconds versus 1500 milliseconds.
ViviFire provides the ability to define units of measure. With this comes compile-time checking of correctness and automatic conversion of values to the expected units.
The representation of a physical quantity has been made to closely resemble the traditional forms used in print. A floating-point number is followed by its unit. The names of all units are case-sensitive—the only part of ViviFire where this happens.
You can specify multiplication in two ways. You can write names with spaces between them, which is common in mathematics. Alternatively, you can use a special operator, written as an asterisk between two hyphens (-*-).
You can also write division in two ways. You can write the word Per between units. Alternatively, you can use a special operator, written as a forward slash between two hyphens (-/-). The advantage with the second operator is that whitespace is not necessary.
t1 = 100.0 N m t2 = 100.0 newton-*-meters v0 = 0.0 meters Per second v1 = 10.0 m-/-s
Aliases and SI prefixes
In the physical world, units can have multiple forms, called aliases, where each name can be used interchangably. For example, km is short for kilometer or kilometre.
You can create aliases by listing each form, separated by a space. Additionally, plural forms can easily be specified by placing just the plural suffix in rounded brackets.
You can specify that a unit is an SI unit by placing the modifier [SI] before the keyword Unit. Doing so causes the automatic creation of additional forms with the SI prefixes of magnitude. For a single-letter name, the short prefixes (such as "k-") are prepended. For longer names, the full prefixes (such as "kilo-") are prepended.
Multiple units can have the same name if each unit is derived from different bases. However, when this happens, these units cannot be used to define a variable or parameter to a procedure because of the ambiguity. Therefore, you should try to define aliases that do not conflict.
[SI] Unit meter(s) metre(s) m
The preceding statement creates the following forms:
- meter, yottameter, zettameter, exameter, petameter, terameter, gigameter, megameter, kilometer, hectometer, decameter, decimeter, centimeter, millimeter, micrometer, nanometer, picometer, femtometer, attometer, zeptometer, and yoctometer
- meters, yottameters, zettameters, exameters, petameters, terameters, gigameters, megameters, kilometers, hectometers, decameters, decimeters, centimeters, millimeters, micrometers, nanometers, picometers, femtometers, attometers, zeptometers, and yoctometers
- metre, yottametre, zettametre, exametre, petametre, terametre, gigametre, megametre, kilometre, hectometre, decametre, decimetre, centimetre, millimetre, micrometre, nanometre, picometre, femtometre, attometre, zeptometre, and yoctometre
- metres, yottametres, zettametres, exametres, petametres, terametres, gigametres, megametres, kilometres, hectometres, decametres, decimetres, centimetres, millimetres, micrometres, nanometres, picometres, femtometres, attometres, zeptometres, and yoctometres
- m, Ym, Zm, Em, Pm, Tm, Gm, Mm, km, hm, dam, dm, cm, mm, µm, um, nm, pm, fm, am, zm, and ym.