module Station.Units directives { units.strict = strict units.unitless = explicit } dimension Length dimension Time quantity Rainfall = Length quantity Speed = Length / Time unit m: Length unit km: Length = 1000.0 * m unit s: Time unit mm: Rainfall unit cm: Rainfall = 10.0 * mm unit mps: Speed = m / s fn speed(distance: f64, duration: f64) -> f64 = distance / duration fn scale(factor: f64<>, value: f64) -> f64 = factor * value node GustDistance = 1500.0 node GustTime = 60.0 node GustSpeed = speed(GustDistance, GustTime) node Track = 2.0 node TrackInMetres = convert>(Track) node Combined = GustDistance + TrackInMetres node Doubled = scale(2.0<>, GustDistance) node Share: f64<> = GustDistance / TrackInMetres node Rain = 12.5 node Shower = 1.0 node ShowerInMillimetres = convert>(Shower) node RainTotal = Rain + ShowerInMillimetres node RawSpeed = strip_unit(GustSpeed) node Limit = attach_unit>(30.0<>) node WithinLimit = GustSpeed <= Limit test UnitsBehave { expect GustSpeed : OK with value = 25.0 within 0.001 expect TrackInMetres : OK with value = 2000.0 within 0.001 expect Combined : OK with value = 3500.0 within 0.001 expect Doubled : OK with value = 3000.0 within 0.001 expect RainTotal : OK with value = 22.5 within 0.001 expect RawSpeed : OK with value = 25.0 within 1e-9 expect WithinLimit : OK with value = true }