Expand description
Quantities: an exact magnitude carrying a physical Dimension and a unit.
A quantity is a number with a unit — 2 inches, 5 kilograms, 9.8 m/s². Internally a
Quantity stores its magnitude in the SI base unit for its dimension (metres, kilograms,
seconds, …) as an exact Rational, so:
- addition/subtraction require the SAME dimension and just add magnitudes,
- multiplication/division combine dimensions (
Length × Length = Area), - conversion to another unit of the same dimension is exact (
÷ scale, offset-aware), and - converting across dimensions (
Length → Mass) is impossible — the forbidden cast.
Because every unit’s scale to the SI base is an exact rational (1 inch = 127/5000 m exactly),
the whole thing is lossless: 2 inches + 5 centimetres is 63/625 m, which in feet is exactly
42/127. A Unit may be affine (a nonzero offset, like °C/°F), so a temperature converts
with scale AND offset; linear units have offset = 0.
Modules§
- constants
- Physical constants as first-class
Quantityvalues — each carries its dimension, so they compose with units under the same dimensional algebra (E = m·c²type-checks, andccan be asked forin kilometres_per_hour). The post-2019-SI defining constants are EXACT rationals (the SI fixes their numeric values); measured constants (G) use their CODATA value. - units
- The unit catalog — every scale an EXACT rational to the SI base. Organized by dimension.
(Irrational-scaled units like
parsec(648000/π·AU) andmachare intentionally omitted until a float-backed quantity exists; everything here is lossless.) A later wave moves this to a growable data file; the math and the names are settled here first.
Structs§
- Position
- A point in 3-D space, coordinates in metres (an inertial frame’s axes). Euclidean distance
is transcendental (a square root), so positions are
f64— the one place the time tower leaves the exact-rational world, because the geometry of spacetime demands it. - Quantity
- An exact quantity: a magnitude in the SI base unit, tagged with its dimension.
- Spacetime
Stamp - A space-aware timestamp — when (a SmoothUTC instant, nanoseconds) AND where (a position in space). This is the heart of the light-cone model: two events can only be causally ordered if their time separation is at least the light-travel time between their positions. Closer in time than that and they are spacelike-separated — genuinely concurrent, no signal could connect them, which is exactly where CRDTs (conflict-free, order-free merge) are the right tool.
- Unit
- A unit of measurement: its dimension and how to map a value in this unit to the SI base.
si = value · scale + offset. Linear units haveoffset = 0; affine units (°C, °F) do not.
Enums§
- Causal
Relation - How two
SpacetimeStamps relate causally.Before:selfis in the past light cone of the other (a signal fromselfcould reach it).After: the reverse.Concurrent: spacelike — neither can have affected the other.
Functions§
- light_
travel_ time - The light-travel time across a distance —
distance / c, exact. Returns a Time quantity, orNoneifdistanceis not a length (the dimensional guard). This is the core of “universal / space-travel time”: the delay before an event at distancedis observed elsewhere (Earth↔Sun ≈ 499 s, Earth↔Mars ≈ 3–22 min). The result rides the exact rational tower, so it never drifts. - lorentz_
factor - The special-relativistic Lorentz factor
γ = 1/√(1 − β²)for a speedβas a fraction ofc.Nonefor|β| ≥ 1(or NaN) — nothing reaches or exceeds light speed. Inherently a float (relativity is transcendental), unlike the exact-rational quantity arithmetic. - observed_
arrival_ nanos - The instant (nanoseconds since the epoch) at which an event happening at
event_nanosis observed by someone a distance away —event + distance/c. The relativistic light-delay the space-travel time model is built on.Noneifdistanceis not a length or the result overflows. - proper_
time_ seconds - The proper time (in seconds) a clock experiences over
coordinate_secondsof coordinate time while moving at speedβ(fraction ofc):coordinate / γ. A moving clock ticks slow — this is the space-traveller’s “time attenuation”.Nonefor|β| ≥ 1. - time_
dilation_ factor - The time-dilation factor
γfor a velocity given as a speedQuantity(β derived asv/c).Noneifvelocityis not a speed or is ≥c. - time_
quantity_ to_ nanos - Convert a Time-dimensioned quantity to a whole number of nanoseconds (rounded to the nearest),
the bridge from the exact
Quantityworld to the instant model.Noneifqis not a time, or the result does not fiti64.