The C arithmetic functions below always takes two arguments, while the
Scheme functions can take an arbitrary number. When you need to
invoke them with just one argument, for example to compute the
equivalent of (- x), pass SCM_UNDEFINED as the second
one: scm_difference (x, SCM_UNDEFINED).
Return the sum of all parameter values. Return 0 if called without any parameters.
If called with one argument z1, -z1 is returned. Otherwise the sum of all but the first argument are subtracted from the first argument.
Return the product of all arguments. If called without arguments, 1 is returned.
Divide the first argument by the product of the remaining arguments. If called with one argument z1, 1/z1 is returned.
Return the absolute value of x.
x must be a number with zero imaginary part. To calculate the magnitude of a complex number, use
magnitudeinstead.
Return the maximum of all parameter values.
Return the minimum of all parameter values.
Round the inexact number x towards zero.
Round the inexact number x to the nearest integer. When exactly halfway between two integers, round to the even one.
Like
scm_truncate_numberorscm_round_number, respectively, but these functions take and returndoublevalues.
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
euclidean-quotientreturns the integer q andeuclidean-remainderreturns the real number r such that x = q*y + r and 0 <= r < |y|.euclidean/returns both q and r, and is more efficient than computing each separately. Note that when y > 0,euclidean-quotientreturns floor(x/y), otherwise it returns ceiling(x/y).Note that these operators are equivalent to the R6RS operators
div,mod, anddiv-and-mod.(euclidean-quotient 123 10) ⇒ 12 (euclidean-remainder 123 10) ⇒ 3 (euclidean/ 123 10) ⇒ 12 and 3 (euclidean/ 123 -10) ⇒ -12 and 3 (euclidean/ -123 10) ⇒ -13 and 7 (euclidean/ -123 -10) ⇒ 13 and 7 (euclidean/ -123.2 -63.5) ⇒ 2.0 and 3.8 (euclidean/ 16/3 -10/7) ⇒ -3 and 22/21
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
floor-quotientreturns the integer q andfloor-remainderreturns the real number r such that q = floor(x/y) and x = q*y + r.floor/returns both q and r, and is more efficient than computing each separately. Note that r, if non-zero, will have the same sign as y.When x and y are integers,
floor-remainderis equivalent to the R5RS integer-only operatormodulo.(floor-quotient 123 10) ⇒ 12 (floor-remainder 123 10) ⇒ 3 (floor/ 123 10) ⇒ 12 and 3 (floor/ 123 -10) ⇒ -13 and -7 (floor/ -123 10) ⇒ -13 and 7 (floor/ -123 -10) ⇒ 12 and -3 (floor/ -123.2 -63.5) ⇒ 1.0 and -59.7 (floor/ 16/3 -10/7) ⇒ -4 and -8/21
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
ceiling-quotientreturns the integer q andceiling-remainderreturns the real number r such that q = ceiling(x/y) and x = q*y + r.ceiling/returns both q and r, and is more efficient than computing each separately. Note that r, if non-zero, will have the opposite sign of y.(ceiling-quotient 123 10) ⇒ 13 (ceiling-remainder 123 10) ⇒ -7 (ceiling/ 123 10) ⇒ 13 and -7 (ceiling/ 123 -10) ⇒ -12 and 3 (ceiling/ -123 10) ⇒ -12 and -3 (ceiling/ -123 -10) ⇒ 13 and 7 (ceiling/ -123.2 -63.5) ⇒ 2.0 and 3.8 (ceiling/ 16/3 -10/7) ⇒ -3 and 22/21
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
truncate-quotientreturns the integer q andtruncate-remainderreturns the real number r such that q is x/y rounded toward zero, and x = q*y + r.truncate/returns both q and r, and is more efficient than computing each separately. Note that r, if non-zero, will have the same sign as x.When x and y are integers, these operators are equivalent to the R5RS integer-only operators
quotientandremainder.(truncate-quotient 123 10) ⇒ 12 (truncate-remainder 123 10) ⇒ 3 (truncate/ 123 10) ⇒ 12 and 3 (truncate/ 123 -10) ⇒ -12 and 3 (truncate/ -123 10) ⇒ -12 and -3 (truncate/ -123 -10) ⇒ 12 and -3 (truncate/ -123.2 -63.5) ⇒ 1.0 and -59.7 (truncate/ 16/3 -10/7) ⇒ -3 and 22/21
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
centered-quotientreturns the integer q andcentered-remainderreturns the real number r such that x = q*y + r and -|y/2| <= r < |y/2|.centered/returns both q and r, and is more efficient than computing each separately.Note that
centered-quotientreturns x/y rounded to the nearest integer. When x/y lies exactly half-way between two integers, the tie is broken according to the sign of y. If y > 0, ties are rounded toward positive infinity, otherwise they are rounded toward negative infinity. This is a consequence of the requirement that -|y/2| <= r < |y/2|.Note that these operators are equivalent to the R6RS operators
div0,mod0, anddiv0-and-mod0.(centered-quotient 123 10) ⇒ 12 (centered-remainder 123 10) ⇒ 3 (centered/ 123 10) ⇒ 12 and 3 (centered/ 123 -10) ⇒ -12 and 3 (centered/ -123 10) ⇒ -12 and -3 (centered/ -123 -10) ⇒ 12 and -3 (centered/ 125 10) ⇒ 13 and -5 (centered/ 127 10) ⇒ 13 and -3 (centered/ 135 10) ⇒ 14 and -5 (centered/ -123.2 -63.5) ⇒ 2.0 and 3.8 (centered/ 16/3 -10/7) ⇒ -4 and -8/21
These procedures accept two real numbers x and y, where the divisor y must be non-zero.
round-quotientreturns the integer q andround-remainderreturns the real number r such that x = q*y + r and q is x/y rounded to the nearest integer, with ties going to the nearest even integer.round/returns both q and r, and is more efficient than computing each separately.Note that
round/andcentered/are almost equivalent, but their behavior differs when x/y lies exactly half-way between two integers. In this case,round/chooses the nearest even integer, whereascentered/chooses in such a way to satisfy the constraint -|y/2| <= r < |y/2|, which is stronger than the corresponding constraint forround/, -|y/2| <= r <= |y/2|. In particular, when x and y are integers, the number of possible remainders returned bycentered/is |y|, whereas the number of possible remainders returned byround/is |y|+1 when y is even.(round-quotient 123 10) ⇒ 12 (round-remainder 123 10) ⇒ 3 (round/ 123 10) ⇒ 12 and 3 (round/ 123 -10) ⇒ -12 and 3 (round/ -123 10) ⇒ -12 and -3 (round/ -123 -10) ⇒ 12 and -3 (round/ 125 10) ⇒ 12 and 5 (round/ 127 10) ⇒ 13 and -3 (round/ 135 10) ⇒ 14 and -5 (round/ -123.2 -63.5) ⇒ 2.0 and 3.8 (round/ 16/3 -10/7) ⇒ -4 and -8/21