Next: , Previous: , Up: baselib math ops   [Index]


4.6.4.5 Arithmetic operations

Procedure: + z1
Procedure: * z1

These procedures return the sum or product of their arguments.

(+ 3 4)                 ⇒  7
(+ 3)                   ⇒  3
(+)                     ⇒  0
(+ +inf.0 +inf.0)       ⇒  +inf.0
(+ +inf.0 -inf.0)       ⇒  +nan.0

(* 4)                   ⇒  4
(*)                     ⇒  1
(* 5 +inf.0)            ⇒  +inf.0
(* -5 +inf.0)           ⇒  -inf.0
(* +inf.0 +inf.0)       ⇒  +inf.0
(* +inf.0 -inf.0)       ⇒  -inf.0
(* 0 +inf.0)            ⇒  0 or +nan.0
(* 0 +nan.0)            ⇒  0 or +nan.0
(* 1.0 0)               ⇒  0 or 0.0

For any real number object x that is neither infinite nor NaN:

(+ +inf.0 x)            ⇒  +inf.0
(+ -inf.0 x)            ⇒  -inf.0

For any real number object x:

(+ +nan.0 x)            ⇒  +nan.0

For any real number object x that is not an exact 0:

(* +nan.0 x)            ⇒  +nan.0

If any of these procedures are applied to mixed non–rational real and non–real complex arguments, they either raise an exception with condition type &implementation-restriction or return an unspecified number object.

Implementations that distinguish -0.0 should adopt behavior consistent with the following examples:

(+  0.0 -0.0)           ⇒  0.0
(+ -0.0  0.0)           ⇒  0.0
(+  0.0  0.0)           ⇒  0.0
(+ -0.0 -0.0)           ⇒ -0.0
Procedure: - z
Procedure: - z1 z2 z3

With two or more arguments, this procedures returns the difference of its arguments, associating to the left. With one argument, however, it returns the additive inverse of its argument.

(- 3 4)                 ⇒ -1
(- 3 4 5)               ⇒ -6
(- 3)                   ⇒ -3
(- +inf.0 +inf.0)       ⇒ +nan.0

If this procedure is applied to mixed non–rational real and non–real complex arguments, it either raises an exception with condition type &implementation-restriction or returns an unspecified number object.

Implementations that distinguish -0.0 should adopt behavior consistent with the following examples:

(-  0.0)                ⇒ -0.0
(- -0.0)                ⇒  0.0
(-  0.0 -0.0)           ⇒  0.0
(- -0.0  0.0)           ⇒ -0.0
(-  0.0  0.0)           ⇒  0.0
(- -0.0 -0.0)           ⇒  0.0
Procedure: / z
Procedure: / z1 z2 z3

If all of the arguments are exact, then the divisors must all be nonzero. With two or more arguments, this procedure returns the quotient of its arguments, associating to the left. With one argument, however, it returns the multiplicative inverse of its argument.

(/ 3 4 5)               ⇒ 3/20
(/ 3)                   ⇒ 1/3
(/ 0.0)                 ⇒ +inf.0
(/ 1.0 0)               ⇒ +inf.0
(/ -1 0.0)              ⇒ -inf.0
(/ +inf.0)              ⇒ 0.0
(/ 0 0)                 ⇒ exception &assertion
(/ 3 0)                 ⇒ exception &assertion
(/ 0 3.5)               ⇒ 0.0
(/ 0 0.0)               ⇒ +nan.0
(/ 0.0 0)               ⇒ +nan.0
(/ 0.0 0.0)             ⇒ +nan.0

If this procedure is applied to mixed non–rational real and non–real complex arguments, it either raises an exception with condition type &implementation-restriction or returns an unspecified number object.

Procedure: abs x

Returns the absolute value of its argument.

(abs -7)                 ⇒  7
(abs -inf.0)             ⇒  +inf.0
Procedure: div-and-mod x1 x2
Procedure: div x1 x2
Procedure: mod x1 x2
Procedure: div0-and-mod0 x1 x2
Procedure: div0 x1 x2
Procedure: mod0 x1 x2

These procedures implement number–theoretic integer division and return the results of the corresponding mathematical operations specified in baselib math semantics integer. If x1 and x2 are exact, x2 must be nonzero. In the cases where the mathematical requirements in baselib math semantics integer cannot be satisfied by any number object, either an exception is raised with condition type &implementation-restriction, or unspecified number objects (one for for div, mod, div0 and mod0, two for div-and-mod and div0-and-mod0) are returned.

(div x1 x2)        ⇒ x1 div x2
(mod x1 x2)        ⇒ x1 mod x2

(div-and-mod x1 x2)
⇒ x1 div x2,
   x1 mod x2 ;; two return values

(div0 x1 x2)       ⇒ x1 div_0 x2
(mod0 x1 x2)       ⇒ x1 mod_0 x2

(div0-and-mod0 x1 x2)
⇒ x1 div_0 x2,
   x1 mod_0 x2 ;; two return values
Procedure: gcd n1
Procedure: lcm n1

These procedures return the greatest common divisor or least common multiple of their arguments. The result is always non–negative.

(gcd 32 -36)                    ⇒ 4
(gcd)                           ⇒ 0
(lcm 32 -36)                    ⇒ 288
(lcm 32.0 -36)                  ⇒ 288.0
(lcm)                           ⇒ 1

Next: , Previous: , Up: baselib math ops   [Index]