math

List of symbols:

%, *, +, -, /, abs, rem, rem_euclid

%

Usage: (% int int)

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 (% 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*)

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"))

+

Usage: (+ number*)

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+)

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+)

Divide a sequence of numbers. Requires at least two numbers.

No Examples

abs

Usage: (abs arg)

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))

rem

Usage: (rem int int)

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)

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))