Distance and temperature with scalar units
Carry registered units through checked scalar arithmetic, conversions, literals and typed parameters.
// Requires the updated native Aner development runtime with aner.units.
import aner.units
let room: Point<degC> = 20.0@degC
let warmer = room + 5.0@delta_K
let rise: Quantity<delta_degC> = warmer - room
let distance = 2.0@m + 50.0@cm
let elapsed = 5.0@s
let speed: Quantity<"m/s"> = distance / elapsed
print(room)
print(room.to("K"))
print(warmer)
print(rise)
print(distance)
print(distance.to("cm"))
print(speed)
print(type(speed))
print(dtype(speed))
print(speed.value()) // Explicit raw Float64 boundary; retain speed.unit() alongside it.
print(speed.unit())
fn extend(distance: Quantity<m>, extra: Quantity<m> = 0.5@m) -> Quantity<m> {
return distance + extra
}
print(extend(2.0@m))
print(1.0@m == 100.0@cm)
Make it your experiment.
With Aner installed, save this program as examples/units_basic.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/units_basic.aner
aner run examples/units_basic.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use the updated native Aner development runtime with aner.units, checked Quantity and Point types, unit literals and unit bearing arrays. Older packaged executables may predate these features. These complete examples run locally, contain their input fixtures and need no external service or credentials.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution