11. Mathematics Functions

Table of Contents

11.1. Math functions ↑

The math/ functions accept numbers, and selected functions also accept temporal values. Arguments to a function must all have the same numeric type; mixed integers and floats produce #err <mismatch type>. math/abs also accepts a duration. Each function describes its result and errors below. The namespace includes constants for pi, tau, e, and conversion between degrees and radians.

11.1.1. math/pi ↑

The constant :math/pi is the float 3.141592653589793, the nearest binary64 approximation to pi.

DUST
:math/pi
=
DUST Result
3.141592653589793

11.1.2. math/tau ↑

The constant :math/tau is the float 6.283185307179586, the nearest binary64 approximation to two times pi.

DUST
:math/tau
=
DUST Result
6.283185307179586

11.1.3. math/deg2rad ↑

The constant :math/deg2rad is pi divided by 180, as a float. Multiply degrees by this value to convert them to radians.

DUST
:math/deg2rad
=
DUST Result
0.017453292519943295

11.1.4. math/rad2deg ↑

The constant :math/rad2deg is 180 divided by pi, as a float. Multiply radians by this value to convert them to degrees.

DUST
:math/rad2deg
=
DUST Result
57.29577951308232

11.1.5. math/e ↑

The constant :math/e is the float 2.718281828459045, the nearest binary64 approximation to the base of natural logarithms.

DUST
:math/e
=
DUST Result
2.718281828459045

11.1.6. math/floor ↑

Function

(math/floor n) → float

Returns the greatest integral-valued float less than or equal to n after conversion to a float.

DUST
[(math/floor 1.8) (math/floor -1.2) (math/floor 2)
 (math/floor 0.0) (math/floor 9007199254740993) (math/floor 100000000000000000000.0)]
→
Canonical DUST
(math/floor 1.8)
(math/floor -1.2)
(math/floor 2)
(math/floor 0.0)
(math/floor 9007199254740993)
(math/floor 100000000000000000000.0)
=
DUST Result
1.0
-2.0
2.0
0.0
9007199254740992.0
100000000000000000000.0

11.1.7. math/ceil ↑

Function

(math/ceil n) → float

Returns the least integral-valued float greater than or equal to n after conversion to a float.

DUST
[(math/ceil 1.2) (math/ceil -1.8) (math/ceil 2)
 (math/ceil 0.0) (math/ceil -0.2)
 (math/ceil 9007199254740993) (math/ceil 100000000000000000000.0)]
→
Canonical DUST
(math/ceil 1.2)
(math/ceil -1.8)
(math/ceil 2)
(math/ceil 0.0)
(math/ceil -0.2)
(math/ceil 9007199254740993)
(math/ceil 100000000000000000000.0)
=
DUST Result
2.0
-1.0
2.0
0.0
0.0
9007199254740992.0
100000000000000000000.0

11.1.8. math/round ↑

Function

(math/round n) → integer

Returns the integer nearest to n, rounding halfway cases away from zero.

Integer inputs are returned unchanged. A float whose rounded value is outside the signed 64-bit integer range produces #err <integer overflow>.

DUST
[(math/round 1.4) (math/round 1.5) (math/round 2.5) (math/round -1.5)
 (math/round -2.5) (math/round -1.6) (math/round 0.5) (math/round -0.5)
 (math/round 0.49999999999999994) (math/round -0.5000000000000001) (math/round 7)
 (math/round 9007199254740993) (math/round 9223372036854775807) (math/round -9223372036854775808)
 (math/round -9223372036854776000.0) (math/round 9223372036854775000.0)]
→
Canonical DUST
(math/round 1.4)
(math/round 1.5)
(math/round 2.5)
(math/round -1.5)
(math/round -2.5)
(math/round -1.6)
(math/round 0.5)
(math/round -0.5)
(math/round 0.49999999999999994)
(math/round -0.5000000000000001)
(math/round 7)
(math/round 9007199254740993)
(math/round 9223372036854775807)
(math/round -9223372036854775808)
(math/round -9223372036854776000.0)
(math/round 9223372036854775000.0)
=
DUST Result
1
2
3
-2
-3
-2
1
-1
0
-1
7
9007199254740993
9223372036854775807
-9223372036854775808
-9223372036854775808
9223372036854774784
DUST
(math/round 9223372036854776000.0)
=
DUST Result
#err <integer overflow>

11.1.9. math/rint ↑

Function

(math/rint n) → float

Returns the integral-valued float nearest to n after conversion to a float, choosing the even integer in halfway cases.

The result does not depend on the host's current rounding mode.

DUST
[(math/rint 1.5) (math/rint 2.5) (math/rint -1.5)
 (math/rint -2.5) (math/rint 0.5) (math/rint -0.5)
 (math/rint 7) (math/rint 9007199254740993)]
→
Canonical DUST
(math/rint 1.5)
(math/rint 2.5)
(math/rint -1.5)
(math/rint -2.5)
(math/rint 0.5)
(math/rint -0.5)
(math/rint 7)
(math/rint 9007199254740993)
=
DUST Result
2.0
2.0
-2.0
-2.0
0.0
0.0
7.0
9007199254740992.0

11.1.10. math/trunc ↑

Function

(math/trunc n) → float

Returns n converted to a float with its fractional part discarded, rounding toward zero.

DUST
[(math/trunc 1.8) (math/trunc -1.8) (math/trunc 2) (math/trunc -0.2) (math/trunc 9007199254740993)]
→
Canonical DUST
(math/trunc 1.8)
(math/trunc -1.8)
(math/trunc 2)
(math/trunc -0.2)
(math/trunc 9007199254740993)
=
DUST Result
1.0
-1.0
2.0
0.0
9007199254740992.0

11.1.11. math/pow ↑

Function

(math/pow base exponent) → float

Returns base raised to exponent.

A zero exponent returns 1.0, including when base is zero. A negative base requires an integral-valued exponent after float conversion. A zero base with a negative exponent produces #err <float overflow>.

DUST
[(math/pow 2 3) (math/pow -2 3) (math/pow 9 0.5) (math/pow 0 0) (math/pow 2 -3)]
→
Canonical DUST
(math/pow 2 3)
(math/pow -2 3)
(math/pow 9 0.5)
(math/pow 0 0)
(math/pow 2 -3)
=
DUST Result
8.0
-8.0
#err <mismatch type>
1.0
0.125
DUST
(math/pow -2 0.5)
=
DUST Result
#err <mismatch type>

11.1.12. math/sqrt ↑

Function

(math/sqrt n) → float

Returns the square root of n.

A negative n produces #err <float overflow>. A zero result has the same sign as n.

DUST
[(math/sqrt 0) (math/sqrt 4) (math/sqrt 9.0)]
→
Canonical DUST
(math/sqrt 0)
(math/sqrt 4)
(math/sqrt 9.0)
=
DUST Result
0.0
2.0
3.0

11.1.13. math/cbrt ↑

Function

(math/cbrt n) → float

Returns the real cube root of n, with the same sign as n.

DUST
[(math/round (* 1000000000000.0 (math/cbrt -8))) (math/round (* 1000000000000.0 (math/cbrt 0)))
 (math/round (* 1000000000000.0 (math/cbrt 27)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/cbrt -8)))
(math/round (* 1000000000000.0 (math/cbrt 0)))
(math/round (* 1000000000000.0 (math/cbrt 27)))
=
DUST Result
-2000000000000
0
3000000000000

11.1.14. math/hypot ↑

Function

(math/hypot x y) → float

Returns the square root of x*x + y*y without intermediate overflow or underflow.

An out-of-range final result produces #err <float overflow>.

DUST
[(math/hypot 3 4) (math/hypot -3 -4) (math/hypot 0 0) (math/hypot 0 1.5)]
→
Canonical DUST
(math/hypot 3 4)
(math/hypot -3 -4)
(math/hypot 0 0)
(math/hypot 0 1.5)
=
DUST Result
5.0
5.0
0.0
#err <mismatch type>
DUST
[(math/round (* 1000000000000.0 (/ (math/hypot 1e+308 1e+308) 1e+308)))
 (math/round (* 1000000000000.0 (/ (math/hypot 1e-308 1e-308) 1e-308)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (/ (math/hypot 1e+308 1e+308) 1e+308)))
(math/round (* 1000000000000.0 (/ (math/hypot 1e-308 1e-308) 1e-308)))
=
DUST Result
1414213562373
1414213562373

11.1.15. math/exp ↑

Function

(math/exp n) → float

Returns e raised to n.

DUST
[(math/round (* 1000000000000.0 (math/exp -1))) (math/round (* 1000000000000.0 (math/exp 0)))
 (math/round (* 1000000000000.0 (math/exp 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/exp -1)))
(math/round (* 1000000000000.0 (math/exp 0)))
(math/round (* 1000000000000.0 (math/exp 1)))
=
DUST Result
367879441171
1000000000000
2718281828459

11.1.16. math/exp2 ↑

Function

(math/exp2 n) → float

Returns two raised to n.

DUST
[(math/exp2 -3) (math/exp2 0) (math/exp2 3)]
→
Canonical DUST
(math/exp2 -3)
(math/exp2 0)
(math/exp2 3)
=
DUST Result
0.125
1.0
8.0

11.1.17. math/expm1 ↑

Function

(math/expm1 n) → float

Returns e raised to n minus one, computed without the loss of precision from subtracting one from math/exp's rounded result near zero.

DUST
[(math/round (* 1000000000000.0 (math/expm1 -1))) (math/round (* 1000000000000.0 (math/expm1 0)))
 (math/round (* 1000000000000.0 (math/expm1 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/expm1 -1)))
(math/round (* 1000000000000.0 (math/expm1 0)))
(math/round (* 1000000000000.0 (math/expm1 1)))
=
DUST Result
-632120558829
0
1718281828459

11.1.18. math/log ↑

Function

(math/log n) → float
(math/log n base) → float

Returns the natural logarithm of n, or its logarithm in the supplied base. When base is supplied, both numbers must have the same type. The base must be positive and cannot be one.

A zero or negative n produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/log 0.5))) (math/round (* 1000000000000.0 (math/log 1)))
 (math/round (* 1000000000000.0 (math/log 2)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/log 0.5)))
(math/round (* 1000000000000.0 (math/log 1)))
(math/round (* 1000000000000.0 (math/log 2)))
=
DUST Result
-693147180560
0
693147180560

11.1.19. math/log2 ↑

Function

(math/log2 n) → float

Returns the base-two logarithm of n.

A zero or negative n produces #err <float overflow>.

DUST
[(math/log2 0.5) (math/log2 1) (math/log2 2) (math/log2 8)]
→
Canonical DUST
(math/log2 0.5)
(math/log2 1)
(math/log2 2)
(math/log2 8)
=
DUST Result
-1.0
0.0
1.0
3.0

11.1.20. math/log10 ↑

Function

(math/log10 n) → float

Returns the base-ten logarithm of n.

A zero or negative n produces #err <float overflow>.

DUST
[(math/log10 0.1) (math/log10 1) (math/log10 10) (math/log10 100)]
→
Canonical DUST
(math/log10 0.1)
(math/log10 1)
(math/log10 10)
(math/log10 100)
=
DUST Result
-1.0
0.0
1.0
2.0

11.1.21. math/log1p ↑

Function

(math/log1p n) → float

Returns the natural logarithm of one plus n, computed without the loss of precision from rounding 1 + n near zero.

An n less than or equal to -1 produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/log1p -0.5))) (math/round (* 1000000000000.0 (math/log1p 0)))
 (math/round (* 1000000000000.0 (math/log1p 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/log1p -0.5)))
(math/round (* 1000000000000.0 (math/log1p 0)))
(math/round (* 1000000000000.0 (math/log1p 1)))
=
DUST Result
-693147180560
0
693147180560

11.1.22. math/sin ↑

Function

(math/sin angle) → float

Returns the sine of angle in radians.

DUST
[(math/round (* 1000000000000.0 (math/sin -1))) (math/round (* 1000000000000.0 (math/sin 0)))
 (math/round (* 1000000000000.0 (math/sin 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/sin -1)))
(math/round (* 1000000000000.0 (math/sin 0)))
(math/round (* 1000000000000.0 (math/sin 1)))
=
DUST Result
-841470984808
0
841470984808

11.1.23. math/cos ↑

Function

(math/cos angle) → float

Returns the cosine of angle in radians.

DUST
[(math/round (* 1000000000000.0 (math/cos -1))) (math/round (* 1000000000000.0 (math/cos 0)))
 (math/round (* 1000000000000.0 (math/cos 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/cos -1)))
(math/round (* 1000000000000.0 (math/cos 0)))
(math/round (* 1000000000000.0 (math/cos 1)))
=
DUST Result
540302305868
1000000000000
540302305868

11.1.24. math/tan ↑

Function

(math/tan angle) → float

Returns the tangent of angle in radians.

DUST
[(math/round (* 1000000000000.0 (math/tan -1))) (math/round (* 1000000000000.0 (math/tan 0)))
 (math/round (* 1000000000000.0 (math/tan 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/tan -1)))
(math/round (* 1000000000000.0 (math/tan 0)))
(math/round (* 1000000000000.0 (math/tan 1)))
=
DUST Result
-1557407724655
0
1557407724655

11.1.25. math/asin ↑

Function

(math/asin n) → float

Returns the arc sine of n in radians, in the range from negative pi/2 to pi/2.

An n outside [-1, 1] produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/asin -1))) (math/round (* 1000000000000.0 (math/asin 0)))
 (math/round (* 1000000000000.0 (math/asin 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/asin -1)))
(math/round (* 1000000000000.0 (math/asin 0)))
(math/round (* 1000000000000.0 (math/asin 1)))
=
DUST Result
-1570796326795
0
1570796326795

11.1.26. math/acos ↑

Function

(math/acos n) → float

Returns the arc cosine of n in radians, in the range from zero to pi.

An n outside [-1, 1] produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/acos -1))) (math/round (* 1000000000000.0 (math/acos 0)))
 (math/round (* 1000000000000.0 (math/acos 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/acos -1)))
(math/round (* 1000000000000.0 (math/acos 0)))
(math/round (* 1000000000000.0 (math/acos 1)))
=
DUST Result
3141592653590
1570796326795
0

11.1.27. math/atan ↑

Function

(math/atan n) → float

Returns the arc tangent of n in radians, in the range from negative pi/2 to pi/2.

DUST
[(math/round (* 1000000000000.0 (math/atan -1))) (math/round (* 1000000000000.0 (math/atan 0)))
 (math/round (* 1000000000000.0 (math/atan 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/atan -1)))
(math/round (* 1000000000000.0 (math/atan 0)))
(math/round (* 1000000000000.0 (math/atan 1)))
=
DUST Result
-785398163397
0
785398163397

11.1.28. math/atan2 ↑

Function

(math/atan2 y x) → float

Returns the angle of the point (x, y) in radians, in the range from negative pi to pi, using both signs to select the quadrant.

The y argument comes first. For zero y and positive x or positive zero x, returns zero with y's sign. For zero y and negative x or negative zero x, returns pi with y's sign.

DUST
[(math/round (* 1000000000000.0 (math/atan2 0 1)))
 (math/round (* 1000000000000.0 (math/atan2 1 1)))
 (math/round (* 1000000000000.0 (math/atan2 1 -1)))
 (math/round (* 1000000000000.0 (math/atan2 -1 -1)))
 (math/round (* 1000000000000.0 (math/atan2 -1 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/atan2 0 1)))
(math/round (* 1000000000000.0 (math/atan2 1 1)))
(math/round (* 1000000000000.0 (math/atan2 1 -1)))
(math/round (* 1000000000000.0 (math/atan2 -1 -1)))
(math/round (* 1000000000000.0 (math/atan2 -1 1)))
=
DUST Result
0
785398163397
2356194490192
-2356194490192
-785398163397
DUST
[(math/round (* 1000000000000.0 (math/atan2 0.0 (- 0.0))))
 (math/round (* 1000000000000.0 (math/atan2 (- 0.0) (- 0.0))))
 (math/copy-sign 1.0 (math/atan2 (- 0.0) 0.0))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/atan2 0.0 (- 0.0))))
(math/round (* 1000000000000.0 (math/atan2 (- 0.0) (- 0.0))))
(math/copy-sign 1.0 (math/atan2 (- 0.0) 0.0))
=
DUST Result
3141592653590
-3141592653590
-1.0

11.1.29. math/sinh ↑

Function

(math/sinh n) → float

Returns the hyperbolic sine of n.

DUST
[(math/round (* 1000000000000.0 (math/sinh -1))) (math/round (* 1000000000000.0 (math/sinh 0)))
 (math/round (* 1000000000000.0 (math/sinh 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/sinh -1)))
(math/round (* 1000000000000.0 (math/sinh 0)))
(math/round (* 1000000000000.0 (math/sinh 1)))
=
DUST Result
-1175201193644
0
1175201193644

11.1.30. math/cosh ↑

Function

(math/cosh n) → float

Returns the hyperbolic cosine of n.

DUST
[(math/round (* 1000000000000.0 (math/cosh -1))) (math/round (* 1000000000000.0 (math/cosh 0)))
 (math/round (* 1000000000000.0 (math/cosh 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/cosh -1)))
(math/round (* 1000000000000.0 (math/cosh 0)))
(math/round (* 1000000000000.0 (math/cosh 1)))
=
DUST Result
1543080634815
1000000000000
1543080634815

11.1.31. math/tanh ↑

Function

(math/tanh n) → float

Returns the hyperbolic tangent of n.

DUST
[(math/round (* 1000000000000.0 (math/tanh -1))) (math/round (* 1000000000000.0 (math/tanh 0)))
 (math/round (* 1000000000000.0 (math/tanh 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/tanh -1)))
(math/round (* 1000000000000.0 (math/tanh 0)))
(math/round (* 1000000000000.0 (math/tanh 1)))
=
DUST Result
-761594155956
0
761594155956

11.1.32. math/asinh ↑

Function

(math/asinh n) → float

Returns the inverse hyperbolic sine of n.

DUST
[(math/round (* 1000000000000.0 (math/asinh -1))) (math/round (* 1000000000000.0 (math/asinh 0)))
 (math/round (* 1000000000000.0 (math/asinh 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/asinh -1)))
(math/round (* 1000000000000.0 (math/asinh 0)))
(math/round (* 1000000000000.0 (math/asinh 1)))
=
DUST Result
-881373587020
0
881373587020

11.1.33. math/acosh ↑

Function

(math/acosh n) → float

Returns the nonnegative inverse hyperbolic cosine of n.

An n less than 1 produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/acosh 1))) (math/round (* 1000000000000.0 (math/acosh 2)))
 (math/round (* 1000000000000.0 (math/acosh 3)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/acosh 1)))
(math/round (* 1000000000000.0 (math/acosh 2)))
(math/round (* 1000000000000.0 (math/acosh 3)))
=
DUST Result
0
1316957896925
1762747174039

11.1.34. math/atanh ↑

Function

(math/atanh n) → float

Returns the inverse hyperbolic tangent of n.

An n outside the open interval from -1 to 1 produces #err <float overflow>.

DUST
[(math/round (* 1000000000000.0 (math/atanh -0.5))) (math/round (* 1000000000000.0 (math/atanh 0)))
 (math/round (* 1000000000000.0 (math/atanh 0.5)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/atanh -0.5)))
(math/round (* 1000000000000.0 (math/atanh 0)))
(math/round (* 1000000000000.0 (math/atanh 0.5)))
=
DUST Result
-549306144334
0
549306144334

11.1.35. math/radians ↑

Function

(math/radians degrees) → float

Returns the angle degrees converted to radians.

DUST
[(math/round (* 1000000000000.0 (math/radians -90)))
 (math/round (* 1000000000000.0 (math/radians 0)))
 (math/round (* 1000000000000.0 (math/radians 180)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/radians -90)))
(math/round (* 1000000000000.0 (math/radians 0)))
(math/round (* 1000000000000.0 (math/radians 180)))
=
DUST Result
-1570796326795
0
3141592653590

11.1.36. math/degrees ↑

Function

(math/degrees radians) → float

Returns the angle radians converted to degrees.

DUST
[(math/round (* 1000000000000.0 (math/degrees -1)))
 (math/round (* 1000000000000.0 (math/degrees 0)))
 (math/round (* 1000000000000.0 (math/degrees 1)))]
→
Canonical DUST
(math/round (* 1000000000000.0 (math/degrees -1)))
(math/round (* 1000000000000.0 (math/degrees 0)))
(math/round (* 1000000000000.0 (math/degrees 1)))
=
DUST Result
-57295779513082
0
57295779513082

11.1.37. math/signum ↑

Function

(math/signum n) → float

Returns -1.0 for negative n, 1.0 for positive n, or zero with n's sign for zero.

DUST
[(math/signum -3) (math/signum 0) (math/signum 5.5) (math/signum (- 0.0))]
→
Canonical DUST
(math/signum -3)
(math/signum 0)
(math/signum 5.5)
(math/signum (- 0.0))
=
DUST Result
-1.0
0.0
1.0
0.0

11.1.38. math/copy-sign ↑

Function

(math/copy-sign magnitude sign) → float

Returns the absolute value of magnitude with the sign of sign, including the sign of floating-point zero.

DUST
[(math/copy-sign 3.5 -2) (math/copy-sign -3.5 2) (math/copy-sign 1.0 (math/copy-sign 0 -1))
 (math/copy-sign 2 (- 0.0)) (math/copy-sign -2 0.0)]
→
Canonical DUST
(math/copy-sign 3.5 -2)
(math/copy-sign -3.5 2)
(math/copy-sign 1.0 (math/copy-sign 0 -1))
(math/copy-sign 2 (- 0.0))
(math/copy-sign -2 0.0)
=
DUST Result
#err <mismatch type>
#err <mismatch type>
-1.0
#err <mismatch type>
#err <mismatch type>

11.1.39. math/floor-div ↑

Function

(math/floor-div n d) → integer

Returns the integer quotient of n divided by d, rounded toward negative infinity.

Before division, float arguments are converted to integers by truncating toward zero. An out-of-range conversion or quotient produces #err <integer overflow>. A zero divisor after conversion produces #err <division integer zero>.

DUST
[(math/floor-div 5 3) (math/floor-div -5 3) (math/floor-div 5 -3)
 (math/floor-div -5 -3) (math/floor-div 9223372036854775807 1)
 (math/floor-div -9223372036854775808 1) (math/floor-div 5.9 2.1)
 (math/floor-div -5.9 2.1)]
→
Canonical DUST
(math/floor-div 5 3)
(math/floor-div -5 3)
(math/floor-div 5 -3)
(math/floor-div -5 -3)
(math/floor-div 9223372036854775807 1)
(math/floor-div -9223372036854775808 1)
(math/floor-div 5.9 2.1)
(math/floor-div -5.9 2.1)
=
DUST Result
1
-2
-2
1
9223372036854775807
-9223372036854775808
2
-3
DUST
(math/floor-div -9223372036854775808 -1)
=
DUST Result
#err <integer overflow>

11.1.40. math/floor-mod ↑

Function

(math/floor-mod n d) → integer

Returns the integer remainder of n divided by d using a quotient rounded toward negative infinity.

Before division, float arguments are converted to integers by truncating toward zero. An out-of-range conversion produces #err <integer overflow>. A zero divisor after conversion produces #err <division integer zero>. A nonzero result has the divisor's sign and a smaller magnitude. The quotient need not fit in an integer, so (math/floor-mod -9223372036854775808 -1) returns 0.

DUST
[(math/floor-mod 5 3) (math/floor-mod -5 3) (math/floor-mod 5 -3)
 (math/floor-mod -5 -3) (math/floor-mod -9223372036854775808 -1)
 (math/floor-mod 9223372036854775807 2) (math/floor-mod 5.9 2.1)
 (math/floor-mod -5.9 2.1)]
→
Canonical DUST
(math/floor-mod 5 3)
(math/floor-mod -5 3)
(math/floor-mod 5 -3)
(math/floor-mod -5 -3)
(math/floor-mod -9223372036854775808 -1)
(math/floor-mod 9223372036854775807 2)
(math/floor-mod 5.9 2.1)
(math/floor-mod -5.9 2.1)
=
DUST Result
2
1
-1
-2
0
1
1
1

11.1.41. math/abs ↑

Function

(math/abs value) → value

Returns the absolute value, preserving integer or float kind. The absolute value of the minimum integer overflows and is an error. Durations are also accepted and return a duration; the minimum tick duration likewise overflows. UTC timestamps are rejected.

DUST
(math/abs -3)
(math/abs -0.5)
(math/abs 0)
=
DUST Result
3
0.5
0
DUST
(math/abs -9223372036854775808)
=
DUST Result
#err <integer overflow>

11.1.42. math/sign ↑

Function

(math/sign number) → integer

Returns integer -1, 0, or 1 according to the argument's sign.

DUST
(math/sign -0.5)
(math/sign 0)
(math/sign 42)
=

11.1.43. math/lerp ↑

Function

(math/lerp start end fraction) → float

Returns start + (end - start) * fraction as a float. The fraction is not clamped, so values outside zero through one extrapolate beyond the endpoints.

DUST
(math/lerp 10.0 20.0 0.5)
(math/lerp 10.0 20.0 1.5)
(math/lerp 10 20 0)
=
DUST Result
15.0
25.0
10.0

11.1.44. math/inverse-lerp ↑

Function

(math/inverse-lerp start end value) → float

Returns the fraction locating value between start and end, without clamping. Equal endpoints are an error.

DUST
(math/inverse-lerp 10 20 15)
(math/inverse-lerp 10 20 25)
(math/inverse-lerp 10 20 10)
=
DUST Result
0.5
1.5
0.0
DUST
(math/inverse-lerp 1 1 2)
=
DUST Result
#err <division integer zero>

11.1.45. math/remap ↑

Function

(math/remap input-start input-end output-start output-end value) → float

Maps value from the input interval to the output interval, without clamping. Equal input endpoints are an error. Reversed intervals are accepted.

DUST
(math/remap 0 10 100 200 5)
(math/remap 0 10 100 200 15)
(math/remap 10 0 100 200 5)
=
DUST Result
150.0
250.0
150.0
DUST
(math/remap 1 1 2 3 4)
=
DUST Result
#err <division integer zero>

11.1.46. math/zero? ↑

Function

(math/zero? n) → boolean

Returns true if n is zero, otherwise false.

DUST
(math/zero? 0)
(math/zero? 0.0)
(math/zero? 3)
(math/zero? -2)
(math/zero? 0.5)
(math/zero? -0.5)
(math/zero? -9223372036854775808)
(math/zero? 9223372036854775807)
=
DUST Result
true
true
false
false
false
false
false
false
DUST
{boolean (math/zero? false)
 extra (math/zero? 0 0)
 list (math/zero? [])
 missing (math/zero?)
 null-input (math/zero? null)
 string (math/zero? "0")}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select string}
        {output #err <mismatch type>
         select null-input}
        {output #err <mismatch type>
         select boolean}
        {output #err <mismatch type>
         select list}
        {output #err <arity mismatch>
         select missing}
        {output #err <arity mismatch>
         select extra}]

11.1.47. math/odd? ↑

Function

(math/odd? n) → boolean

Returns true if integer n is odd, otherwise false.

DUST
(math/odd? 1)
(math/odd? 2)
(math/odd? -3)
(math/odd? 0)
(math/odd? -2)
(math/odd? -9223372036854775808)
(math/odd? 9223372036854775807)
=
DUST Result
true
false
true
false
false
false
true
DUST
{boolean (math/odd? true)
 extra (math/odd? 1 3)
 float (math/odd? 1.0)
 fractional (math/odd? 1.5)
 missing (math/odd?)
 null-input (math/odd? null)
 string (math/odd? "1")}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select float}
        {output #err <mismatch type>
         select fractional}
        {output #err <mismatch type>
         select string}
        {output #err <mismatch type>
         select null-input}
        {output #err <mismatch type>
         select boolean}
        {output #err <arity mismatch>
         select missing}
        {output #err <arity mismatch>
         select extra}]

11.1.48. math/even? ↑

Function

(math/even? n) → boolean

Returns true if integer n is even, otherwise false.

DUST
(math/even? 0)
(math/even? 2)
(math/even? -3)
(math/even? 1)
(math/even? -2)
(math/even? -9223372036854775808)
(math/even? 9223372036854775807)
=
DUST Result
true
true
false
false
true
true
false
DUST
{boolean (math/even? false)
 extra (math/even? 2 4)
 float (math/even? 2.0)
 fractional (math/even? 2.5)
 missing (math/even?)
 null-input (math/even? null)
 string (math/even? "2")}
→
Evaluation cases
#cases [{output #err <mismatch type>
         select float}
        {output #err <mismatch type>
         select fractional}
        {output #err <mismatch type>
         select string}
        {output #err <mismatch type>
         select null-input}
        {output #err <mismatch type>
         select boolean}
        {output #err <arity mismatch>
         select missing}
        {output #err <arity mismatch>
         select extra}]

11.1.49. math/min ↑

Function

(math/min value more*) → value

Returns the least argument. Requires at least one argument, and all arguments must have the same numeric or temporal kind. Integer and temporal comparisons retain full 64-bit precision.

DUST
(math/min 3 1 2)
(math/min 1.5 0.5)
(math/min 9007199254740994 9007199254740993)
=
DUST Result
1
0.5
9007199254740993
DUST
(math/min 1 1.0)
=
DUST Result
#err <mismatch type>

11.1.50. math/max ↑

Function

(math/max value more*) → value

Returns the greatest argument. Requires at least one argument, and all arguments must have the same numeric or temporal kind. Integer and temporal comparisons retain full 64-bit precision.

DUST
(math/max 3 1 2)
(math/max 1.5 0.5)
(math/max -9007199254740994 -9007199254740993)
=
DUST Result
3
1.5
-9007199254740993

11.1.51. math/clamp ↑

Function

(math/clamp value low high) → value

Returns value limited to the inclusive interval from low through high. All three arguments must have the same numeric or temporal kind, and low must not exceed high.

DUST
(math/clamp 5 1 3)
(math/clamp -1.0 0.0 1.0)
(math/clamp 2 1 3)
=
DUST Result
3
0.0
2
DUST
(math/clamp 1 2 0)
=
DUST Result
#err <invalid value>