The standard library
Slide 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, cos and tan, and their inverses asin, acos and atan2(y, x), work in radians.
  • sqrt, hypot(x, y) and abs cover distances.
  • min(a, b), max(a, b) and clamp(value, low, high) cover bounds, clamp being exactly min(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)
}