num
Float functions such as sqrt and sin are auto-imported from prelude::math; this module adds the rest. Powers are the ** operator.
Part of coil-stdlib. spool projects get it automatically; with plain coil, pass --root ~/.coil/stdlib/src.
Import what you use (use path::* is not allowed):
use num::{PI, E};
Constants#
| Name | Description |
|---|---|
PI | The circle constant π, as a float. |
E | Euler’s number e, the base of ln, as a float. |
TAU | A full turn τ = 2π, as a float. |
Functions#
| Name | Description |
|---|---|
abs | Returns the absolute value of x. |
min | Returns the smaller of a and b (a when they are equal). |
max | Returns the larger of a and b (a when they are equal). |
round | Rounds x to the nearest whole number; halves round away from zero. |
clamp | Returns x limited to the range lo..=hi. |
signum | Returns -1, 0 or 1 by the sign of x. |
gcd | Returns the greatest common divisor of a and b, which should be non-negative. |
lcm | Returns the least common multiple of a and b, which should be non-negative; 0 when either is 0. |
trunc | Removes the fractional part of x, rounding toward zero. |
fract | Returns the fractional part of x, x - trunc(x); it has the sign of x. |
is_nan | Returns true when x is NaN (0.0 / 0.0, sqrt(-1.0), …). |
is_infinite | Returns true when x is positive or negative infinity. |
is_finite | Returns true when x is neither NaN nor infinite. |
rem_euclid | Returns the remainder of a / b that is never negative: 0 <= r < abs(b). |
div_euclid | Returns the quotient that goes with rem_euclid: a == div_euclid(a, b) * b + rem_euclid(a, b). |
hypot | Returns sqrt(a * a + b * b), the length of the hypotenuse. |