prelude::math
Scalar functions take and return float and follow IEEE-754: an invalid input
gives NaN and an overflow gives infinity, never a panic. Powers and remainders
are the ** and % operators, not functions.
The linear-algebra helpers work on fixed-size arrays ([float; 3],
[[float; 2]; 2]) and check shapes at compile time.
For integer helpers (abs, gcd, clamp, …) and constants such as PI, see
the stdlib num module; for overflow-aware integer
powers, arith.
Built into the compiler.
Types#
| Name | Description |
|---|---|
Matrix | A matrix: nested fixed-length numeric rows with matrix operators. |
Functions#
| Name | Description |
|---|---|
sin | Returns the sine of x (in radians). |
cos | Returns the cosine of x (in radians). |
tan | Returns the tangent of x (in radians). |
sqrt | Returns the square root of x. |
floor | Returns the largest whole number less than or equal to x, as a float. |
ceil | Returns the smallest whole number greater than or equal to x, as a float. |
exp | Returns e raised to the power x. |
ln | Returns the natural logarithm of x. |
atan | Returns the arctangent of x, in radians in -pi/2..=pi/2. |
atan2 | Returns the angle of the point (x, y) from the positive x axis, in radians in -pi..=pi. |
asin | Returns the arcsine of x, in radians in -pi/2..=pi/2. |
acos | Returns the arccosine of x, in radians in 0..=pi. |
log10 | Returns the base-10 logarithm of x. |
log2 | Returns the base-2 logarithm of x. |
cbrt | Returns the cube root of x. |
sinh | Returns the hyperbolic sine of x. |
cosh | Returns the hyperbolic cosine of x. |
tanh | Returns the hyperbolic tangent of x. |
dot | Returns the dot product of two vectors of the same length. |
cross | Returns the cross product of two 3-element vectors. |
matmul | Multiplies two matrices written as nested fixed-length arrays. |
matrix | Wraps nested fixed-length rows as a Matrix. |
intersect | Returns a byte mask that is 1 where both matrices have a non-zero cell. |
diff | Returns a byte mask that is 1 where a has a non-zero cell and b has 0. |