Arithmetic

22.1  Fixnums and flonums

Fixnum and flonum arithmetic is already supported by many systems, mainly for efficiency. Standardization of fixnum and flonum arithmetic increases the portability of code that uses it. Standardizing the precision of fixnum and flonum arithmetic would make it inefficient on some systems, which would defeat its purpose. Therefore, R6RS specifies the syntax and much of the semantics of fixnum and flonum arithmetic, but makes the precision implementation-dependent.

Existing implementations employ different implementation strategies for fixnums: Some implement the model specified by R6RS (overflows cause exceptions), some implement modular arithmetic (overflows “wrap around”), and others do not handle arithmetic overflows at all. The latter model violates the safety requirement of R6RS. In programs that use fixnums instead of generic arithmetic, overflows are typically programming mistakes. The model chosen for R6RS has the advantage that such overflows do not get silently converted into meaningless number objects, and that the programs gets notified of the violation through the exception system.

22.2  Bitwise operations

The bitwise operations have been adapted from the operations described in SRFIs 33 [29] and 60 [19].

22.3  Notes on individual procedures

fl+ and fl*

These procedures are restricted to two arguments because their generalizations to three or more arguments would require precision proportional to the number of arguments.

real->flonum

This procedure is necessary because not all real number objects are inexact, and some inexact real number objects may not be flonums.

flround

The flround procedure rounds to even for consistency with the default rounding mode specified by the IEEE floating-point standard.

flsqrt

The behavior of flsqrt on - 0.0 is consistent with the IEEE floating-point standard.