The standard librarySlide 50 of 85
50mathThe standard library
Math
hive.math is pure, and every one of its functions takes and answers with a Float — there is no integer twin, because Hive never widens a number behind your back.
pi()is the one constant.sin,cosandtan, and their inversesasin,acosandatan2(y, x), work in radians.sqrt,hypot(x, y)andabscover distances.min(a, b),max(a, b)andclamp(value, low, high)cover bounds,clampbeing exactlymin(max(value, low), high)— so a range given backwards answers with the high bound.
None of it reports an error: a value outside a function's domain answers with whatever non-finite Float the arithmetic produces, such as NaN for sqrt(-1.0).
proc main(): void {
radius := 3.0
area := hive.math.pi() * radius ** 2.0
echo area
echo hive.math.sqrt(hive.math.hypot(3.0, 4.0))
echo hive.math.max(hive.math.min(2.0, 5.0), 1.0)
echo hive.math.clamp(120.0, 0.0, 100.0)
}You can edit this program and run it here.Tab indents, Escape leaves the program, and Ctrl+Enter runs it.