These functions can be used to modify or read the floating point modes:
The keyword arguments to
set-floating-point-modes set various
modes controlling how floating point arithmetic is done:
A list of the exception conditions that should
cause traps. Possible exceptions are
:divide-by-zero. Initially all traps except
are enabled. See float-traps.
The rounding mode to use when the result
is not exact. Possible values are
Initially, the rounding mode is
:nearest. See the warning in
section float-rounding-modes about use of other rounding
exception keywords used to set the exception flags. The
current-exceptions are the exceptions for the previous
operation, so setting it is not very useful. The
accrued-exceptions are a cumulative record of the exceptions
that occurred since the last time these flags were cleared.
() will clear any accrued exceptions.
Set the hardware’s “fast mode” flag, if
any. When set, IEEE conformance or debuggability may be impaired.
Some machines may not have this feature, in which case the value
nil. Sparc platforms support a fast mode where
denormal numbers are silently truncated to zero.
If a keyword argument is not supplied, then the associated state is not changed.
get-floating-point-modes returns a list representing the
state of the floating point modes. The list is in the same format
as the keyword arguments to
apply could be used with
restore the modes in effect at the time of the call to
To make handling control of floating-point exceptions, the following macro is useful.
body is executed with the selected floating-point exceptions
traps masked out (disabled).
traps should be
a list of possible floating-point exceptions that should be ignored.
Possible values are
This is equivalent to saving the current traps from
get-floating-point-modes, setting the floating-point modes to
the desired exceptions, running the
body, and restoring the
saved floating-point modes. The advantage of this macro is that it
causes less consing to occur.
Some points about the with-float-traps-masked:
Of these the latter is the most portable because on the alpha port it is not possible to enable some traps at run-time.
x86::float-wait) if using the lisp conditions to catch trap within a
handler-bindmacro does the right thing and inserts a float-wait (at the end of its body on the x86). The masking and noting of exceptions is also safe here.
(set (floating-point-modes)...)VOPs. These VOPs blindly update the flags which may include other state. We assume this state hasn’t changed in between getting and setting the state. For example, if you used the FP unit between the above calls, the state may be incorrectly restored! The
with-float-traps-maskedmacro keeps the intervening code to a minimum and uses only integer operations.