Math
Integer helpers, square roots, mapping, GCD, and LCM.
import "lib/math.nbl";
Functions without an 8 or 16 suffix operate on nibble arguments.
math_isqrt returns the largest r with r*r <= n. math_sqrt16 returns the
same result for a 16-bit input, with a char result. math_map8 clamps input
outside in_min..in_max.
Functions
Call |
Returns |
Notes |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
a * b, with a and b in 0..15. The result fits in a char. |
|
|
Quotient and remainder for nibble / nibble. |
|
|
|
|
|
char / nibble. The quotient can be up to 255. |
|
|
|
|
|
Largest r with r*r <= n. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unsigned linear map. Values outside in_min..in_max are clamped. |
|
|
Largest r with r*r <= n; the result fits in a char. |
|
|
|
|
|
|
|
|
Raw two’s-complement sign: 15 = -1, 0 = zero, 1 = +1. |
|
|
|
|
|