Next: stdlib arithmetic exact bitwise, Previous: stdlib arithmetic fixnums, Up: stdlib arithmetic [Index]
This section describes the (rnrs arithmetic flonums (6))
library.
This section uses fl, fl1, fl2, etc., as parameter
names for arguments that must be flonums, and ifl as a name for
arguments that must be integer–valued flonums, i.e., flonums for which
the integer-valued?
predicate returns true.
Return #t
if obj is a flonum, #f
otherwise.
Return the best flonum representation of x.
The value returned is a flonum that is numerically closest to the argument.
NOTE If flonums are represented in binary floating point, then implementations should break ties by preferring the floating–point representation whose least significant bit is zero.
These procedures return #t
if their arguments are (respectively):
equal, monotonically increasing, monotonically decreasing, monotonically
nondecreasing, or monotonically nonincreasing, #f
otherwise.
These predicates must be transitive.
(fl=? +inf.0 +inf.0) ⇒ #t (fl=? -inf.0 +inf.0) ⇒ #f (fl=? -inf.0 -inf.0) ⇒ #t (fl=? 0.0 -0.0) ⇒ #t (fl<? 0.0 -0.0) ⇒ #f (fl=? +nan.0 fl) ⇒ #f (fl<? +nan.0 fl) ⇒ #f
These numerical predicates test a flonum for a particular property,
returning #t
or #f
:
flinteger?
procedure tests whether the number object is an integer,
flzero?
tests whether it is fl=?
to zero,
flpositive?
tests whether it is greater than zero,
flnegative?
tests whether it is less than zero,
flodd?
tests whether it is odd,
fleven?
tests whether it is even,
flfinite?
tests whether it is not an infinity and not a NaN,
flinfinite?
tests whether it is an infinity,
flnan?
tests whether it is a NaN.
(flnegative? -0.0) ⇒ #f (flfinite? +inf.0) ⇒ #f (flfinite? 5.0) ⇒ #t (flinfinite? 5.0) ⇒ #f (flinfinite? +inf.0) ⇒ #t
NOTE
(flnegative? -0.0)
must return#f
, else it would lose the correspondence with(fl< -0.0 0.0)
, which is#f
according to IEEE 754.
These procedures return the maximum or minimum of their arguments. They always return a NaN when one or more of the arguments is a NaN.
These procedures return the flonum sum or product of their flonum arguments. In general, they should return the flonum that best approximates the mathematical sum or product. (For implementations that represent flonums using IEEE binary floating point, the meaning of “best” is defined by the IEEE standards.)
(fl+ +inf.0 -inf.0) ⇒ +nan.0 (fl+ +nan.0 fl) ⇒ +nan.0 (fl* +nan.0 fl) ⇒ +nan.0
With two or more arguments, these procedures return the flonum difference or quotient of their flonum arguments, associating to the left.
With one argument, however, they return the additive or multiplicative flonum inverse of their argument.
In general, they should return the flonum that best approximates the mathematical difference or quotient. (For implementations that represent flonums using IEEE binary floating point, the meaning of “best” is reasonably well–defined by the IEEE standards.)
(fl- +inf.0 +inf.0) ⇒ +nan.0
For undefined quotients, fl/
behaves as specified by the IEEE
standards:
(fl/ 1.0 0.0) ⇒ +inf.0 (fl/ -1.0 0.0) ⇒ -inf.0 (fl/ 0.0 0.0) ⇒ +nan.0
Return the absolute value of fl.
These procedures implement number–theoretic integer division and return the results of the corresponding mathematical operations specified in report section baselib math semantics integer.
In the cases where the mathematical requirements in baselib math semantics cannot be satisfied by any number object, either an exception
is raised with condition type &implementation-restriction
, or
unspecified flonums (one for fldiv
, flmod
, fldiv0
and flmod0
, two for fldiv-and-mod
and
fldiv0-and-mod0
) are returned.
(fldiv fl1 fl2) ⇒ fl1 div fl2 (flmod fl1 fl2) ⇒ fl1 mod fl2 (fldiv-and-mod fl1 fl2) ⇒ fl1 div fl2, fl1 mod fl2 ; two return values (fldiv0 fl1 fl2) ⇒ fl1 div_0 fl2 (flmod0 fl1 fl2) ⇒ fl1 mod_0 fl2 (fldiv0-and-mod0 fl1 fl2) ⇒ fl1 div_0 fl2, fl1 mod_0 fl2 ; two return values
These procedures return the numerator or denominator of fl as a flonum; the result is computed as if fl was represented as a fraction in lowest terms. The denominator is always positive. The denominator of 0.0 is defined to be 1.0.
(flnumerator +inf.0) ⇒ +inf.0 (flnumerator -inf.0) ⇒ -inf.0 (fldenominator +inf.0) ⇒ 1.0 (fldenominator -inf.0) ⇒ 1.0 (flnumerator 0.75) ⇒ 3.0 ; probably (fldenominator 0.75) ⇒ 4.0 ; probably
Implementations should implement following behavior:
(flnumerator -0.0) ⇒ -0.0
These procedures return integral flonums for flonum arguments that are not infinities or NaNs.
flfloor
Returns the largest integral flonum not larger than fl.
flceiling
Returns the smallest integral flonum not smaller than fl.
fltruncate
Returns the integral flonum closest to fl whose absolute value is not larger than the absolute value of fl.
flround
Returns the closest integral flonum to fl, rounding to even when fl represents a number halfway between two integers.
Although infinities and NaNs are not integer objects, these procedures return an infinity when given an infinity as an argument, and a NaN when given a NaN:
(flfloor +inf.0) ⇒ +inf.0 (flceiling -inf.0) ⇒ -inf.0 (fltruncate +nan.0) ⇒ +nan.0
These procedures compute the usual transcendental functions.
flexp
Computes the base-E exponential of fl.
fllog
With a single argument computes the natural logarithm of fl (not
the base ten logarithm); (fllog fl1 fl2)
computes
the base–fl2 logarithm of fl1.
flasin
flacos
flatan
Compute arcsine, arccosine, and arctangent, respectively. (flatan
fl1 fl2)
computes the arc tangent of fl1/fl2.
baselib math ops trascend for the underlying mathematical operations. In the event that these operations do not yield a real result for the given arguments, the result may be a NaN, or may be some unspecified flonum.
Implementations that use IEEE binary floating–point arithmetic should follow the relevant standards for these procedures.
(flexp +inf.0) ⇒ +inf.0 (flexp -inf.0) ⇒ 0.0 (fllog +inf.0) ⇒ +inf.0 (fllog 0.0) ⇒ -inf.0 (fllog -0.0) ⇒ unspecified ; if -0.0 is distinguished (fllog -inf.0) ⇒ +nan.0 (flatan -inf.0) ⇒ -1.5707963267948965 ; approximately (flatan +inf.0) ⇒ 1.5707963267948965 ; approximately
Returns the principal square root of fl. For -0.0,
flsqrt
should return -0.0; for other negative arguments,
the result may be a NaN or some unspecified flonum.
(flsqrt +inf.0) ⇒ +inf.0 (flsqrt -0.0) ⇒ -0.0
Either fl1 should be non–negative, or, if fl1 is negative, fl2 should be an integer object.
The flexpt
procedure returns fl1 raised to the power
fl2. If fl1 is negative and fl2 is not an integer
object, the result may be a NaN, or may be some unspecified flonum.
If fl1 and fl2 are both zero, the result is 1.0. If fl1 is zero and fl2 is positive, the result is zero. If fl1 is negative, the result may be a NaN, or may be some unspecified flonum.
These condition types could be defined by the following code:
(define-condition-type &no-infinities &implementation-restriction make-no-infinities-violation no-infinities-violation?) (define-condition-type &no-nans &implementation-restriction make-no-nans-violation no-nans-violation?)
These types describe that a program has executed an arithmetic operations that is specified to return an infinity or a NaN, respectively, on a Scheme implementation that is not able to represent the infinity or NaN. baselib math infinities.
Return a flonum that is numerically closest to fx.
NOTE The result of this procedure may not be numerically equal to fx, because the fixnum precision may be greater than the flonum precision.
Next: stdlib arithmetic exact bitwise, Previous: stdlib arithmetic fixnums, Up: stdlib arithmetic [Index]