Skip to main content

Units Reference

A lookup table, not a tutorial — Types & Units covers how unit arithmetic actually behaves. Every unit below works as a numeric literal suffix (5ft, 20kg) using its abbreviation, and as a type annotation using either the abbreviation or the full name:

equivalence.stof
#[main]
fn main() {
  const a: km = 3km;
  const b: kilometers = 3km;
  pln(a == b);

  pln(135cm + 5ft + 123in as m);
}
Output

When two compatible-but-different units combine in an expression, the result takes on whichever of the two units is larger — mixed angles always resolve to radians specifically, regardless of size.

Length

UnitFull Name
kmkilometers
hmhectometers
dcmdecameters
mmeters
dmdecimeters
cmcentimeters
mmmillimeters
ummicrometers
nmnanometers
mimiles
ydyards
ftfeet
ininches

Mass

UnitFull Name
Gtgigatonnes
Mtmegatonnes
ttonnes
kgkilograms
ggrams
mgmilligrams
ugmicrograms
ngnanograms
pgpicograms
Tontons
lblbs (imperial pounds)
ozounces

Time

UnitFull Name
daydays
hrhours
minminutes
sseconds
msmilliseconds
usmicroseconds
nsnanoseconds

Time.now() returns a plain ms value for exactly this reason — subtracting or adding any other time unit against it just works.

Temperature

UnitFull Name
Kkelvin
Ccelsius
Ffahrenheit

Angles

UnitFull NameRange
radradiansclamped to ±360° equivalent
degdegreesclamped to ±360°
pradpradians (positive radians)clamped to [0°, 360°)
pdegpdegrees (positive degrees)clamped to [0°, 360°)

The positive variants exist for comparisons where sign shouldn't matter — casting -90deg to pdeg gives 270deg, not -90deg.

Memory — Decimal

UnitFull Name
bit / bits
byte / bytes
KBkilobytes
MBmegabytes
GBgigabytes
TBterabytes
PBpetabytes
EBexabytes
ZBzettabytes
YByottabytes

Memory — Binary

UnitFull Name
KiBkibibytes
MiBmebibytes
GiBgibibytes
TiBtebibytes
PiBpebibytes
EiBexbibytes
ZiBzebibytes
YiByobibytes

Stof keeps these two tables separate on purpose — MB and MiB get conflated constantly in casual use, but they're not the same size, and the gap between them widens at larger scales. If a config or a docs page you're reading says GB but means GiB (common, and usually implied by context in computing), casting to the unit you actually meant is one step either way.