math
List of symbols:
%, *, euler, pi, +, -, /, 2pow, abs, arccos, arcsin, arctan, ceil, cos, exp, floor, fract, log, log2, max, min, pow, rem, rem-euclid, round, sin, sqrt, tan
%
Usage: (% int int)
Namespace: root
Remainder from dividing (arg 1) by (arg 2).
Note: Remainder and Modulo are two similar mathematical operations,
called rem
and rem-euclid
.
This function uses rem
which is the same as the %
operator in C.
With rem
, the sign of the result is the same as the dividend (arg 1).
With rem-euclid
, the sign of the result is always positive.
Example:
(test::assert-equal 0 (% 50 10))
(test::assert-equal 5 (% 55 10))
(test::assert-equal 1 (% 1 2))
(test::assert-equal -1 (% -10 3))
(test::assert-equal 1 (% 10 -3))
(test::assert-equal -1 (% -10 -3))
(test::assert-error (%))
(test::assert-error (% 1))
(test::assert-error (% 1 2 3))
(test::assert-error (% 1 2.0))
*
Usage: (* number*)
Namespace: root
Multiply a sequence of numbers. (*) will return 1.
Example:
(test::assert-equal 1 (*))
(test::assert-equal 5 (* 5))
(test::assert-equal 5 (* 1 5))
(test::assert-equal 5.0 (* 1.0 5))
(test::assert-equal 7.5 (* 1.5 5))
(test::assert-equal 7.5 (* 1.5 5.0))
(test::assert-equal 15 (* 3 5))
(test::assert-equal 8 (* 1 2 4))
(test::assert-equal 16 (* 2 2 4))
(test::assert-equal 16.0 (* 2 2.0 4))
(test::assert-equal 16.0 (* 2.0 2.0 4.0))
(test::assert-equal 54.9999999999999 (* 100 0.55))
(test::assert-error (* 1 2 4 "5"))
euler
Usage: (prn euler)
Namespace: root
Float representing euler’s number.
Example:
(test::assert-equal 2.718281828459045 *euler*)
pi
Usage: (prn pi)
Namespace: root
Float representing pi.
Example:
(test::assert-equal 3.141592653589793 *pi*)
+
Usage: (+ number*)
Namespace: root
Add a sequence of numbers. (+) will return 0.
Example:
(test::assert-equal 0 (+))
(test::assert-equal 5 (+ 5))
(test::assert-equal 10 (+ 5 5))
(test::assert-equal 6 (+ 1 5))
(test::assert-equal 6.5 (+ 1 5.5))
(test::assert-equal 7 (+ 1 2 4))
(test::assert-error (+ 1 2 4 "5"))
-
Usage: (- number+)
Namespace: root
Subtract a sequence of numbers. Requires at least one number (negate if only one number).
Example:
(test::assert-error (- 5 "2"))
(test::assert-equal -5 (- 5))
(test::assert-equal -5.0 (- 5.0))
(test::assert-equal -4 (- 1 5))
(test::assert-equal -4.5 (- 1 5.5))
(test::assert-equal 4 (- 10 2 4))
(test::assert-equal 4.5 (- 10 2 3.5))
/
Usage: (/ number+)
Namespace: root
Divide a sequence of numbers. Requires at least two numbers.
No Examples
2pow
Usage: (2pow base)
Namespace: root
Raise 2 to power of argument.
Example:
(test::assert-compare == 1024 (2pow 10))
(test::assert-compare == (2pow (* 10 2)) (pow (2pow 10) 2))
abs
Usage: (abs arg)
Namespace: root
Returns absolute value of arg.
Example:
(test::assert-equal 2 (abs 2))
(test::assert-equal 144 (abs -144))
(test::assert-equal 4.53 (abs -4.53))
(test::assert-equal 36028797018963967 (abs -36028797018963967))
arccos
Usage: (arccos value)
Namespace: root
Calculate the arccosine (inverse cosine) of a value. Returns angle in radians. Value must be between -1 and 1.
Example:
(test::assert-true (< 1.570 (arccos 0) 1.571))
(test::assert-equal 0.0 (arccos 1))
(test::assert-true (< 3.141 (arccos -1) 3.142))
(test::assert-error (arccos))
(test::assert-error (arccos 2))
(test::assert-error (arccos -2))
arcsin
Usage: (arcsin value)
Namespace: root
Calculate the arcsine (inverse sine) of a value. Returns angle in radians. Value must be between -1 and 1.
Example:
(test::assert-equal 0.0 (arcsin 0))
(test::assert-true (< 1.570 (arcsin 1) 1.571))
(test::assert-true (< -1.571 (arcsin -1) -1.570))
(test::assert-error (arcsin))
(test::assert-error (arcsin 2))
(test::assert-error (arcsin -2))
arctan
Usage: (arctan value)
Namespace: root
Calculate the arctangent (inverse tangent) of a value. Returns angle in radians.
Example:
(test::assert-equal 0.0 (arctan 0))
(test::assert-true (< 0.785 (arctan 1) 0.786))
(test::assert-true (< -0.786 (arctan -1) -0.785))
(test::assert-error (arctan))
(test::assert-error (arctan 1 2))
ceil
Usage: (ceil num)
Namespace: root
Round a number up to the nearest integer.
Example:
(test::assert-compare == 3 (ceil 2.1))
(test::assert-compare == 3 (ceil 2.9))
(test::assert-compare == -2 (ceil -2.1))
(test::assert-compare == -2 (ceil -2.9))
(test::assert-compare == 5 (ceil 5))
(test::assert-error (ceil))
(test::assert-error (ceil 1 2))
cos
Usage: (cos radians)
Namespace: root
Calculate the cosine of an angle in radians.
Example:
(test::assert-equal 1.0 (cos 0))
(test::assert-true (< 0.540 (cos 1) 0.541))
(test::assert-true (< -1.001 (cos 3.14159) -0.999))
(test::assert-error (cos))
(test::assert-error (cos 1 2))
exp
Usage: (exp power)
Namespace: root
Calculate e raised to the given power.
Example:
(test::assert-equal 1.0 (exp 0))
(test::assert-true (< 2.718 (exp 1) 2.719))
(test::assert-true (< 7.389 (exp 2) 7.390))
(test::assert-error (exp))
(test::assert-error (exp 1 2))
floor
Usage: (floor num)
Namespace: root
Round a number down to the nearest integer.
Example:
(test::assert-compare == 2 (floor 2.1))
(test::assert-compare == 2 (floor 2.9))
(test::assert-compare == -3 (floor -2.1))
(test::assert-compare == -3 (floor -2.9))
(test::assert-compare == 5 (floor 5))
(test::assert-error (floor))
(test::assert-error (floor 1 2))
fract
Usage: (fract num)
Namespace: root
Get the fractional part of a number.
Example:
(test::assert-true (< 0.099 (fract 2.1) 0.101))
(test::assert-true (< 0.899 (fract 2.9) 0.901))
(test::assert-compare == 0 (fract 5))
(test::assert-true (< -0.901 (fract -2.9) -0.899))
(test::assert-true (< -0.101 (fract -2.1) -0.099))
(test::assert-error (fract))
(test::assert-error (fract 1 2))
log
Usage: (log num [base])
Namespace: root
Calculate logarithm of num. If base is not provided, uses natural logarithm (base e).
Example:
(test::assert-equal 0.0 (log 1))
(test::assert-true (< 2.302 (log 10) 2.303))
(test::assert-equal 3.0 (log 8 2))
(test::assert-equal 2.0 (log 100 10))
(test::assert-error (log))
(test::assert-error (log -1))
(test::assert-error (log 10 -2))
log2
Usage: (log2 num)
Namespace: root
Calculate base-2 logarithm of num.
Example:
(test::assert-equal 0.0 (log2 1))
(test::assert-equal 3.0 (log2 8))
(test::assert-equal 10.0 (log2 1024))
(test::assert-error (log2))
(test::assert-error (log2 -1))
(test::assert-error (log2 0))
max
Usage: (max number+)
Namespace: root
Return the maximum value from one or more numbers.
Example:
(test::assert-equal 3 (max 1 2 3))
(test::assert-equal 10 (max 10 -5 3))
(test::assert-equal 42 (max 42))
(test::assert-equal 3.0 (max 3.0 1.5 2.0))
(test::assert-equal 3.0 (max 1 2.0 3))
(test::assert-error (max))
(test::assert-error (max 1 "two"))
min
Usage: (min number+)
Namespace: root
Return the minimum value from one or more numbers.
Example:
(test::assert-equal 1 (min 1 2 3))
(test::assert-equal -5 (min 10 -5 3))
(test::assert-equal 42 (min 42))
(test::assert-equal 1.5 (min 3.0 1.5 2.0))
(test::assert-equal 1 (min 1 2.0 3))
(test::assert-error (min))
(test::assert-error (min 1 "two"))
pow
Usage: (pow base power)
Namespace: root
Raise first argument to power of second argument.
Example:
(test::assert-equal 16.0 (pow 4 2))
(test::assert-equal 1024.0 (pow 2 10))
(test::assert-equal 1.0 (pow 85 0))
(test::assert-equal 0.25 (pow 2 -2))
(test::assert-error (pow))
(test::assert-error (pow 2))
(test::assert-error (pow 2 3 4))
rem
Usage: (rem int int)
Namespace: root
Remainder from dividing (arg 1) by (arg 2).
Note: Remainder and Modulo are two similar mathematical operations,
called rem
and rem-euclid
in Rust.
This function uses rem
which is the same as the %
operator in C.
With rem
, the sign of the result is the same as the dividend (arg 1).
With rem-euclid
, the sign of the result is always positive.
Example:
(test::assert-equal 0 (rem 50 10))
(test::assert-equal 5 (rem 55 10))
(test::assert-equal 1 (rem 1 2))
(test::assert-equal -1 (rem -10 3))
(test::assert-equal 1 (rem 10 -3))
(test::assert-equal -1 (rem -10 -3))
(test::assert-error (rem))
(test::assert-error (rem 1))
(test::assert-error (rem 1 2 3))
(test::assert-error (rem 1 2.0))
rem-euclid
Usage: (rem-euclid int int)
Namespace: root
Least Non-negative number that can be added to a multiple of the divisor (arg 2) to get the dividend (arg 1).
The result should always be 0 <= result < divisor (arg 2).
Note: Remainder and Modulo are two similar mathematical operations,
called rem
and rem-euclid
in Rust.
With rem
, the sign of the result is the same as the dividend (arg 1).
With rem-euclid
, the sign of the result is always positive.
Example:
(test::assert-equal 0 (rem-euclid 50 10))
(test::assert-equal 5 (rem-euclid 55 10))
(test::assert-equal 1 (rem-euclid 1 2))
(test::assert-equal 2 (rem-euclid -10 3))
(test::assert-equal 1 (rem-euclid 10 -3))
(test::assert-equal 2 (rem-euclid -10 -3))
(test::assert-error (rem-euclid))
(test::assert-error (rem-euclid 1))
(test::assert-error (rem-euclid 1 2 3))
(test::assert-error (rem-euclid 1 2.0))
round
Usage: (round num)
Namespace: root
Round a number to the nearest integer, with ties rounding away from zero.
Example:
(test::assert-compare == 2 (round 2.1))
(test::assert-compare == 3 (round 2.9))
(test::assert-compare == 3 (round 2.5))
(test::assert-compare == -2 (round -2.1))
(test::assert-compare == -3 (round -2.9))
(test::assert-compare == -3 (round -2.5))
(test::assert-compare == 5 (round 5))
(test::assert-error (round))
(test::assert-error (round 1 2))
sin
Usage: (sin radians)
Namespace: root
Calculate the sine of an angle in radians.
Example:
(test::assert-equal 0.0 (sin 0))
(test::assert-true (< 0.841 (sin 1) 0.842))
(test::assert-true (< -0.001 (sin 3.14159) 0.001))
(test::assert-error (sin))
(test::assert-error (sin 1 2))
sqrt
Usage: (sqrt num)
Namespace: root
Take square root of argument.
Example:
(test::assert-equal 2.0 (sqrt 4))
(test::assert-equal 12.0 (sqrt 144))
(test::assert-true (< 2.049 (sqrt 4.2) 2.050))
(test::assert-error (sqrt))
(test::assert-error (sqrt 4 2))
(test::assert-error (sqrt -4))
tan
Usage: (tan radians)
Namespace: root
Calculate the tangent of an angle in radians.
Example:
(test::assert-equal 0.0 (tan 0))
(test::assert-true (< 1.557 (tan 1) 1.558))
(test::assert-true (< -0.001 (tan 3.14159) 0.001))
(test::assert-error (tan))
(test::assert-error (tan 1 2))