Science
vunits
Converts and adds lengths, masses and times within the same dimension.
Released v1.0.0 · 2026-09-28use "stdlib/units.ven"
From a table of units such as the mile.
print map_get(unit_table(), "mile")
:: ("m", 1609.344)
Reference (10 functions)
API reference
unit_table()
Builds the conversion table mapping every known unit to its base unit and factor.
map_get(unit_table(), "mile")
:: ("m", 1609.344)unit_info(unit)
Looks up units (base_unit, factor) entry, raising for an unknown unit.
unit_info("mile")
:: ("m", 1609.344)is_compatible(unit_a, unit_b)
Tests whether two units measure the same dimension.
is_compatible("mile", "km")
:: yesquantity(value, unit)
Builds a Quantity, validating that unit is a known unit first.
quantity(5.0, "mile")
Quantity(value: 5.0, unit: "mile")convert(q, target_unit)
Converts q to target_unit, raising if the two units measure different dimensions.
convert(quantity(1.0, "mile"), "m")
Quantity(value: 1609.344, unit: "m")add(a, b)
Adds two Quantities, converting b onto as unit first.
add(quantity(1.0, "km"), quantity(500.0, "m"))
Quantity(value: 1.5, unit: "km")subtract(a, b)
Subtracts b from a, converting b onto as unit first.
subtract(quantity(2.0, "km"), quantity(500.0, "m"))
Quantity(value: 1.5, unit: "km")scaled(q, factor)
Multiplies qs value by a plain scalar factor, keeping its unit.
scaled(quantity(3.0, "m"), 2.0)
Quantity(value: 6.0, unit: "m")