11. Mathematics Functions
Table of Contents
- 11.1. Math functions
- 11.1.1. math/pi
- 11.1.2. math/tau
- 11.1.3. math/deg2rad
- 11.1.4. math/rad2deg
- 11.1.5. math/e
- 11.1.6. math/floor
- 11.1.7. math/ceil
- 11.1.8. math/round
- 11.1.9. math/rint
- 11.1.10. math/trunc
- 11.1.11. math/pow
- 11.1.12. math/sqrt
- 11.1.13. math/cbrt
- 11.1.14. math/hypot
- 11.1.15. math/exp
- 11.1.16. math/exp2
- 11.1.17. math/expm1
- 11.1.18. math/log
- 11.1.19. math/log2
- 11.1.20. math/log10
- 11.1.21. math/log1p
- 11.1.22. math/sin
- 11.1.23. math/cos
- 11.1.24. math/tan
- 11.1.25. math/asin
- 11.1.26. math/acos
- 11.1.27. math/atan
- 11.1.28. math/atan2
- 11.1.29. math/sinh
- 11.1.30. math/cosh
- 11.1.31. math/tanh
- 11.1.32. math/asinh
- 11.1.33. math/acosh
- 11.1.34. math/atanh
- 11.1.35. math/radians
- 11.1.36. math/degrees
- 11.1.37. math/signum
- 11.1.38. math/copy-sign
- 11.1.39. math/floor-div
- 11.1.40. math/floor-mod
- 11.1.41. math/abs
- 11.1.42. math/sign
- 11.1.43. math/lerp
- 11.1.44. math/inverse-lerp
- 11.1.45. math/remap
- 11.1.46. math/zero?
- 11.1.47. math/odd?
- 11.1.48. math/even?
- 11.1.49. math/min
- 11.1.50. math/max
- 11.1.51. math/clamp
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.
11.1.2. math/tau ↑
The constant :math/tau is the float 6.283185307179586, the nearest binary64 approximation to two times pi.
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.
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.
11.1.5. math/e ↑
The constant :math/e is the float 2.718281828459045, the nearest binary64 approximation to the base of natural logarithms.
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.
[(math/floor 1.8) (math/floor -1.2) (math/floor 2) (math/floor 0.0) (math/floor 9007199254740993) (math/floor 100000000000000000000.0)]
(math/floor 1.8) (math/floor -1.2) (math/floor 2) (math/floor 0.0) (math/floor 9007199254740993) (math/floor 100000000000000000000.0)
1.0 -2.0 2.0 0.0 9007199254740992.0 100000000000000000000.0
(math/ceil n) → float
Returns the least integral-valued float greater than or equal to n after conversion to a float.
[(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)]
(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)
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>.
[(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)]
(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)
1 2 3 -2 -3 -2 1 -1 0 -1 7 9007199254740993 9223372036854775807 -9223372036854775808 -9223372036854775808 9223372036854774784
(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.
[(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)]
(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)
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.
[(math/trunc 1.8) (math/trunc -1.8) (math/trunc 2) (math/trunc -0.2) (math/trunc 9007199254740993)]
(math/trunc 1.8) (math/trunc -1.8) (math/trunc 2) (math/trunc -0.2) (math/trunc 9007199254740993)
1.0 -1.0 2.0 0.0 9007199254740992.0
(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>.
[(math/pow 2 3) (math/pow -2 3) (math/pow 9 0.5) (math/pow 0 0) (math/pow 2 -3)]
(math/pow 2 3) (math/pow -2 3) (math/pow 9 0.5) (math/pow 0 0) (math/pow 2 -3)
8.0 -8.0 #err <mismatch type> 1.0 0.125
(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.
[(math/sqrt 0) (math/sqrt 4) (math/sqrt 9.0)]
(math/sqrt 0) (math/sqrt 4) (math/sqrt 9.0)
0.0 2.0 3.0
(math/cbrt n) → float
Returns the real cube root of n, with the same sign as n.
[(math/round (* 1000000000000.0 (math/cbrt -8))) (math/round (* 1000000000000.0 (math/cbrt 0))) (math/round (* 1000000000000.0 (math/cbrt 27)))]
(math/round (* 1000000000000.0 (math/cbrt -8))) (math/round (* 1000000000000.0 (math/cbrt 0))) (math/round (* 1000000000000.0 (math/cbrt 27)))
-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>.
[(math/hypot 3 4) (math/hypot -3 -4) (math/hypot 0 0) (math/hypot 0 1.5)]
(math/hypot 3 4) (math/hypot -3 -4) (math/hypot 0 0) (math/hypot 0 1.5)
5.0 5.0 0.0 #err <mismatch type>
[(math/round (* 1000000000000.0 (/ (math/hypot 1e+308 1e+308) 1e+308))) (math/round (* 1000000000000.0 (/ (math/hypot 1e-308 1e-308) 1e-308)))]
(math/round (* 1000000000000.0 (/ (math/hypot 1e+308 1e+308) 1e+308))) (math/round (* 1000000000000.0 (/ (math/hypot 1e-308 1e-308) 1e-308)))
1414213562373 1414213562373
(math/exp n) → float
Returns e raised to n.
[(math/round (* 1000000000000.0 (math/exp -1))) (math/round (* 1000000000000.0 (math/exp 0))) (math/round (* 1000000000000.0 (math/exp 1)))]
(math/round (* 1000000000000.0 (math/exp -1))) (math/round (* 1000000000000.0 (math/exp 0))) (math/round (* 1000000000000.0 (math/exp 1)))
367879441171 1000000000000 2718281828459
(math/exp2 n) → float
Returns two raised to n.
[(math/exp2 -3) (math/exp2 0) (math/exp2 3)]
(math/exp2 -3) (math/exp2 0) (math/exp2 3)
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.
[(math/round (* 1000000000000.0 (math/expm1 -1))) (math/round (* 1000000000000.0 (math/expm1 0))) (math/round (* 1000000000000.0 (math/expm1 1)))]
(math/round (* 1000000000000.0 (math/expm1 -1))) (math/round (* 1000000000000.0 (math/expm1 0))) (math/round (* 1000000000000.0 (math/expm1 1)))
-632120558829 0 1718281828459
(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>.
[(math/round (* 1000000000000.0 (math/log 0.5))) (math/round (* 1000000000000.0 (math/log 1))) (math/round (* 1000000000000.0 (math/log 2)))]
(math/round (* 1000000000000.0 (math/log 0.5))) (math/round (* 1000000000000.0 (math/log 1))) (math/round (* 1000000000000.0 (math/log 2)))
-693147180560 0 693147180560
(math/log2 n) → float
Returns the base-two logarithm of n.
A zero or negative n produces #err <float overflow>.
[(math/log2 0.5) (math/log2 1) (math/log2 2) (math/log2 8)]
(math/log2 0.5) (math/log2 1) (math/log2 2) (math/log2 8)
-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>.
[(math/log10 0.1) (math/log10 1) (math/log10 10) (math/log10 100)]
(math/log10 0.1) (math/log10 1) (math/log10 10) (math/log10 100)
-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>.
[(math/round (* 1000000000000.0 (math/log1p -0.5))) (math/round (* 1000000000000.0 (math/log1p 0))) (math/round (* 1000000000000.0 (math/log1p 1)))]
(math/round (* 1000000000000.0 (math/log1p -0.5))) (math/round (* 1000000000000.0 (math/log1p 0))) (math/round (* 1000000000000.0 (math/log1p 1)))
-693147180560 0 693147180560
(math/sin angle) → float
Returns the sine of angle in radians.
[(math/round (* 1000000000000.0 (math/sin -1))) (math/round (* 1000000000000.0 (math/sin 0))) (math/round (* 1000000000000.0 (math/sin 1)))]
(math/round (* 1000000000000.0 (math/sin -1))) (math/round (* 1000000000000.0 (math/sin 0))) (math/round (* 1000000000000.0 (math/sin 1)))
-841470984808 0 841470984808
(math/cos angle) → float
Returns the cosine of angle in radians.
[(math/round (* 1000000000000.0 (math/cos -1))) (math/round (* 1000000000000.0 (math/cos 0))) (math/round (* 1000000000000.0 (math/cos 1)))]
(math/round (* 1000000000000.0 (math/cos -1))) (math/round (* 1000000000000.0 (math/cos 0))) (math/round (* 1000000000000.0 (math/cos 1)))
540302305868 1000000000000 540302305868
(math/tan angle) → float
Returns the tangent of angle in radians.
[(math/round (* 1000000000000.0 (math/tan -1))) (math/round (* 1000000000000.0 (math/tan 0))) (math/round (* 1000000000000.0 (math/tan 1)))]
(math/round (* 1000000000000.0 (math/tan -1))) (math/round (* 1000000000000.0 (math/tan 0))) (math/round (* 1000000000000.0 (math/tan 1)))
-1557407724655 0 1557407724655
(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>.
[(math/round (* 1000000000000.0 (math/asin -1))) (math/round (* 1000000000000.0 (math/asin 0))) (math/round (* 1000000000000.0 (math/asin 1)))]
(math/round (* 1000000000000.0 (math/asin -1))) (math/round (* 1000000000000.0 (math/asin 0))) (math/round (* 1000000000000.0 (math/asin 1)))
-1570796326795 0 1570796326795
(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>.
[(math/round (* 1000000000000.0 (math/acos -1))) (math/round (* 1000000000000.0 (math/acos 0))) (math/round (* 1000000000000.0 (math/acos 1)))]
(math/round (* 1000000000000.0 (math/acos -1))) (math/round (* 1000000000000.0 (math/acos 0))) (math/round (* 1000000000000.0 (math/acos 1)))
3141592653590 1570796326795 0
(math/atan n) → float
Returns the arc tangent of n in radians, in the range from negative pi/2 to pi/2.
[(math/round (* 1000000000000.0 (math/atan -1))) (math/round (* 1000000000000.0 (math/atan 0))) (math/round (* 1000000000000.0 (math/atan 1)))]
(math/round (* 1000000000000.0 (math/atan -1))) (math/round (* 1000000000000.0 (math/atan 0))) (math/round (* 1000000000000.0 (math/atan 1)))
-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.
[(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)))]
(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)))
0 785398163397 2356194490192 -2356194490192 -785398163397
[(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))]
(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))
3141592653590 -3141592653590 -1.0
(math/sinh n) → float
Returns the hyperbolic sine of n.
[(math/round (* 1000000000000.0 (math/sinh -1))) (math/round (* 1000000000000.0 (math/sinh 0))) (math/round (* 1000000000000.0 (math/sinh 1)))]
(math/round (* 1000000000000.0 (math/sinh -1))) (math/round (* 1000000000000.0 (math/sinh 0))) (math/round (* 1000000000000.0 (math/sinh 1)))
-1175201193644 0 1175201193644
(math/cosh n) → float
Returns the hyperbolic cosine of n.
[(math/round (* 1000000000000.0 (math/cosh -1))) (math/round (* 1000000000000.0 (math/cosh 0))) (math/round (* 1000000000000.0 (math/cosh 1)))]
(math/round (* 1000000000000.0 (math/cosh -1))) (math/round (* 1000000000000.0 (math/cosh 0))) (math/round (* 1000000000000.0 (math/cosh 1)))
1543080634815 1000000000000 1543080634815
(math/tanh n) → float
Returns the hyperbolic tangent of n.
[(math/round (* 1000000000000.0 (math/tanh -1))) (math/round (* 1000000000000.0 (math/tanh 0))) (math/round (* 1000000000000.0 (math/tanh 1)))]
(math/round (* 1000000000000.0 (math/tanh -1))) (math/round (* 1000000000000.0 (math/tanh 0))) (math/round (* 1000000000000.0 (math/tanh 1)))
-761594155956 0 761594155956
11.1.32. math/asinh ↑
Function(math/asinh n) → float
Returns the inverse hyperbolic sine of n.
[(math/round (* 1000000000000.0 (math/asinh -1))) (math/round (* 1000000000000.0 (math/asinh 0))) (math/round (* 1000000000000.0 (math/asinh 1)))]
(math/round (* 1000000000000.0 (math/asinh -1))) (math/round (* 1000000000000.0 (math/asinh 0))) (math/round (* 1000000000000.0 (math/asinh 1)))
-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>.
[(math/round (* 1000000000000.0 (math/acosh 1))) (math/round (* 1000000000000.0 (math/acosh 2))) (math/round (* 1000000000000.0 (math/acosh 3)))]
(math/round (* 1000000000000.0 (math/acosh 1))) (math/round (* 1000000000000.0 (math/acosh 2))) (math/round (* 1000000000000.0 (math/acosh 3)))
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>.
[(math/round (* 1000000000000.0 (math/atanh -0.5))) (math/round (* 1000000000000.0 (math/atanh 0))) (math/round (* 1000000000000.0 (math/atanh 0.5)))]
(math/round (* 1000000000000.0 (math/atanh -0.5))) (math/round (* 1000000000000.0 (math/atanh 0))) (math/round (* 1000000000000.0 (math/atanh 0.5)))
-549306144334 0 549306144334
11.1.35. math/radians ↑
Function(math/radians degrees) → float
Returns the angle degrees converted to radians.
[(math/round (* 1000000000000.0 (math/radians -90))) (math/round (* 1000000000000.0 (math/radians 0))) (math/round (* 1000000000000.0 (math/radians 180)))]
(math/round (* 1000000000000.0 (math/radians -90))) (math/round (* 1000000000000.0 (math/radians 0))) (math/round (* 1000000000000.0 (math/radians 180)))
-1570796326795 0 3141592653590
11.1.36. math/degrees ↑
Function(math/degrees radians) → float
Returns the angle radians converted to degrees.
[(math/round (* 1000000000000.0 (math/degrees -1))) (math/round (* 1000000000000.0 (math/degrees 0))) (math/round (* 1000000000000.0 (math/degrees 1)))]
(math/round (* 1000000000000.0 (math/degrees -1))) (math/round (* 1000000000000.0 (math/degrees 0))) (math/round (* 1000000000000.0 (math/degrees 1)))
-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.
[(math/signum -3) (math/signum 0) (math/signum 5.5) (math/signum (- 0.0))]
(math/signum -3) (math/signum 0) (math/signum 5.5) (math/signum (- 0.0))
-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.
[(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)]
(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)
#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>.
[(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)]
(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)
1 -2 -2 1 9223372036854775807 -9223372036854775808 2 -3
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.
[(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)]
(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)
2 1 -1 -2 0 1 1 1
(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.
(math/sign number) → integer
Returns integer -1, 0, or 1 according to the argument's sign.
(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.
(math/lerp 10.0 20.0 0.5) (math/lerp 10.0 20.0 1.5) (math/lerp 10 20 0)
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.
(math/inverse-lerp 10 20 15) (math/inverse-lerp 10 20 25) (math/inverse-lerp 10 20 10)
0.5 1.5 0.0
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.
(math/remap 0 10 100 200 5) (math/remap 0 10 100 200 15) (math/remap 10 0 100 200 5)
150.0 250.0 150.0
11.1.46. math/zero? ↑
Function(math/zero? n) → boolean
Returns true if n is zero, otherwise false.
(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)
true true false false false false false false
{boolean (math/zero? false) extra (math/zero? 0 0) list (math/zero? []) missing (math/zero?) null-input (math/zero? null) string (math/zero? "0")}
#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}]
(math/odd? n) → boolean
Returns true if integer n is odd, otherwise false.
(math/odd? 1) (math/odd? 2) (math/odd? -3) (math/odd? 0) (math/odd? -2) (math/odd? -9223372036854775808) (math/odd? 9223372036854775807)
true false true false false false true
{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")}
#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.
(math/even? 0) (math/even? 2) (math/even? -3) (math/even? 1) (math/even? -2) (math/even? -9223372036854775808) (math/even? 9223372036854775807)
true true false false true true false
{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")}
#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}]
(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.
(math/min 3 1 2) (math/min 1.5 0.5) (math/min 9007199254740994 9007199254740993)
1 0.5 9007199254740993
(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.
(math/max 3 1 2) (math/max 1.5 0.5) (math/max -9007199254740994 -9007199254740993)
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.