Unit Statement
Identifies a unit of measure.
Syntax
Usual construct
[ modifiers ] _
Unit unit_names [ = expression ]
Interval-scale construct
[ modifiers ] _
Unit unit_names ( parameter In unit ) = expression
Parts
modifiers- Optional one or more modifiers.
You can put modifiers together on one line, or put each one on a different line.
@Deprecated– If you try to use the unit, the result is a compiler warning. See @Deprecated for more information.@SI– The unit is an SI (metric) unit. You can supply one of three optional attributes:@SI BINARY– Gives these prefixes:kibi Ki(2^10),mebi Mi(2^20),gibi Gi(2^30),tebi Ti(2^40),pebi Ti(2^50),exbi Ei(2^60),zebi Zi(2^70),yobi Yi(2^80).@SI LARGE– Gives these prefixes:deca deka da(10^1),hecto h(10^2),kilo k(10^3),mega M(10^6),giga G(10^9),tera T(10^12),peta P(10^15),exa E(10^18),zetta Z(10^21),yotta Y(10^24),ronna R(10^27),quetta Q(10^30).@SI SMALL– Gives these prefixes:deci d(10^−1),centi c(10^−2),milli m(10^−3),micro µ μ u(10^−6),nano n(10^−9),pico p(10^−12),femto f(10^−15),atto a(10^−18),zepto z(10^−21),yocto y(10^−24),ronto r(10^−27),quecto q(10^−30).
LARGEandsmallput together.@Interval– The unit is on an interval scale. You can add or subtract the value, but you cannot multiply it. And the value zero is not without something to measure.You must use (1) the interval-scale construct or (2) the attribute
NonNeg.@interval NonNeg– The unit cannot have a negative value. If you try to make a negative value, the result is an error.
unit_names- Mandatory one or more names with spaces between each.
All names identify the same unit.
Unit name
[ number ] { name | name + suffix | prefix - name }name- Mandatory basic name for a unit of measure.
number- One of the integer literals that follow:
1–nameis irregular and grammatically singular. For example, «1 foot».2–nameis irregular and grammatically plural. For example, «2 feet».0–nameis grammatically singular for zero and one. This occurs in some languages, for example, French. You can use0(and no others) withsuffixorprefix.
suffix- Mandatory after
+. Identifies the regular plural suffix forname. For example, «metre+s» or «inch+es». prefix- Mandatory before a hyphen (
-). Identifies the regular plural prefix forname. This occurs in some languages, most frequently in Africa. For example, in Swahili, «ma-debe».
expression- A conversion factor.
- Optional in the usual construct.
- Mandatory in the interval-scale construct.
parameter- Mandatory in the interval-scale construct.
You use it with
expressionfor a unit with an interval scale, for example, a unit of temperature. unit- A different unit that is related to this unit.
Instructions
TODO
Examples
// Make meter, metres, kilometer, millimetres, m, km, mm ...
@SI Unit meter+s metre+s m
// Derived unit.
Unit light_year+s ly = 9.4605284 petameters
// in. is not permitted because IN is a keyword
// and a name cannot have a period,
// but you can write IN between backticks.
Unit inch+es `in` = 2.54 cm
// Kelvin cannot be negative or plural.
@Interval NonNeg
Unit Kelvin K
// °C is not given because it is not easy to write.
// 1 makes a singular name and 2 makes a plural name.
// This is an interval-scale unit, thus the parameter k.
// Also gets the range check from Kelvin.
Unit Celsius 1 degree_C 2 degrees_C (k In Kelvin) =
k + 273.15
// Make second, secs, milliseconds, s, ms, ...
@SI SMALL Unit second+s sec+s s
// Make byte, kibibytes, mebibyte, B, KiB, MiB, ...
// Does not permit Kilobyte, megabytes, KB, MB, ...
@SI BINARY Unit byte+s B