srfi.94 - Type-restricted numerical functions ¶This module provides arithmetic functions specialized for exact integers
and reals. Similar to scheme.fixnum (see scheme.fixnum - R7RS fixnums)
and scheme.flonum (see scheme.flonum - R7RS flonum) in a sense of restricting
types of range and domains, but this srfi procedures cover wider range
(e.g. real-* procedures can accept all real numbers include
exact integers, and integer-* procedures can accept both fixnums
and bignums).
This module is provided mostly for the completeness. Generally useful
procedures are already built-in, so you don’t need to use this
module to use them. Furthermore, some SRFI-94 procedures have the
same name of Gauche’s built-in but behave slightly differently, so
just importing everything from srfi.94 may cause unexpected effect.
If you need certain srfi-94 specific procedures, we recommend you to import
them selectively.
The following procedures are built-in. See Arithmetics for the details.
real-exp real-tan atan make-rectangular real-ln real-asin real-sqrt make-polar real-sin real-acos integer-expt real-cos real-atan real-expt
The following procedures are redefined in this module, shadowing Gauche’s built-in procedures. See the description of each entry for the difference.
quotient modulo remainder mod abs
[SRFI-94]{srfi.94}
The arguments must be nonnegative reals. Returns logarithm of x
with base base, computed as
(/ (real-ln x) (real-ln base)).
Note that R7RS’s log takes x first, then optional base.
Gauche doesn’t provide this procedure as built-in to avoid confusion.
[SRFI-94]{srfi.94}
This is the same as exact-integer-sqrt (see Arithmetics).
[SRFI-94]{srfi.94}
Both arguments must be exact integers, and base must be
positive, while x must be nonnegative.
Returns a maximum exact integer n such that (<= (expt base n) k).
The order of arguments is the same as real-log—not log.
(integer-log 2 1500) ⇒ 10
[SRFI-94]{srfi.94}
While Gauche’s built-in abs can take a non-real number
(in which case, it acts like magnitude), this version
throws an error.
[SRFI-94]{srfi.94}
Real version of quotient, modulo, and remainder
(see Arithmetics).
Returns quotient, modulo, and remainder of n divided by d. Arguments doesn’t need to be integers. If both are exact, the result is exact.
quo returns (truncate (/ n d)).
rem returns (- n (* d (quo n d))).
mod returns (- n (* d (floor (/ n d)))).
Note: R6RS introduced different divison operators, div and mod
(see Arithmetics).
They can take non-integer arguments, but unfortunately, they behave
differently from SRFI-94.
[SRFI-94]{srfi.94}
SRFI-94 version of these procedures throws an error if the arguments
are not exact integers. Otherwise they behave the same
as built-in (see Arithmetics).