0.7.0
The first release. UCUM, the Unified Code for Units of Measure, for Elixir: read, check, convert and name unit codes as the standard defines them.
Reads all of UCUM (spec/01)
- Its whole grammar: products, quotients, a leading
/, integer exponents and factors, terms in parentheses to any depth (g/(m.s2)), the atoms10*and10^(10*3/uL), and annotations ({request}/s), which have no unit meaning. - Its essence table itself, version 2.2 (2024-06-17):
priv/ucum-essence.xml, Regenstrief's file unmodified, from which the library is compiled. All 24 prefixes and 312 units, with UCUM's print symbols; no definition is written by hand. - The 41 arbitrary units (
[IU],[arb'U]), each a dimension of its own that converts only to itself. - The case-insensitive codes, through
case_sensitive/1(MM[HG]ismm[Hg]). - A code's numbers have a bound, 2⁶⁵⁵³⁶, decided before anything is computed, so
km999999is{:too_large, code}at once instead of exhausting the machine; what cancels between a code's components cancels first (km999999/km999999is{1, 1}).
Answers (spec/02)
parse/1,valid?/1,dimension/1in UCUM's seven base dimensions, the exactfactor/1(a rational, π kept as a power),kind/1,symbol/2,name/1(in the form of the UCUM functional tests:km/his(kilometer) / (hour)) andcanonical/1.conversion/2, the exact scale and offset between two codes, andconvert/3, a value between them, through every special unit's function as well (dB,Np,[pH],dB[SPL],[p'diop], the homeopathic potencies).convert/2applies a resolved conversion to a value without reading the codes again, for converting many values.multiply/2anddivide/2: the product and quotient of two quantities, in base units.- The table's own lookups:
atom/1,prefix/1,atoms/0,prefixes/0.
Exact, and never past a float's range (spec/02 §9)
- A value is taken as the exact number it is, the scale and offset are exact, and the
answer is rounded once: the nearest float. π is held to 576 bits, so a π scale rounds
once too (
[pi]1000in10*497is the nearest float). - An answer past a float's range is
{:error, :out_of_range}(with the value and codes fromconvert/3), not anArithmeticError; one inside it is given whatever the size of its parts (the integer 10⁴⁰⁰mis 10.010*399.m); integers of any size are values.
Errors are values (spec/00 §3, spec/03)
- Every function answers
{:ok, value}or{:error, reason}, its!twin the value orUcum.Error, and nothing else raises, for an argument of any shape.format_error/1writes any reason as a sentence, and a refusal costs no more to write than to answer: a caller's term is shown in at most 40 characters.
Conformance (spec/04)
- The UCUM functional tests (Ucum-java's
UcumFunctionalTests.xml, 573 cases) run with the test suite: 572 of 573 pass. The one that does not names the empty string, which the file and UCUM's grammar themselves call no code (spec/04 §3).
No runtime dependency, no process, no state, no file read. Elixir 1.18 or later.