Previous: Floating Point Rounding Mode, Up: Floats [Contents][Index]
These functions can be used to modify or read the floating point modes:
:traps
:rounding-mode
:fast-mode
:accrued-exceptions
:current-exceptions
¶The keyword arguments to set-floating-point-modes
set various
modes controlling how floating point arithmetic is done:
:traps
A list of the exception conditions that should
cause traps. Possible exceptions are :underflow
,
:overflow
, :inexact
, :invalid
and
:divide-by-zero
. Initially all traps except :inexact
are enabled. See float-traps.
:rounding-mode
The rounding mode to use when the result
is not exact. Possible values are :nearest
,
:positive-infinity
, :negative-infinity
and :zero
.
Initially, the rounding mode is :nearest
. See the warning in
section float-rounding-modes about use of other rounding
modes.
:current-exceptions
, :accrued-exceptions
Lists of
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.
Specifying ()
will clear any accrued exceptions.
:fast-mode
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
is always 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 set-floating-point-modes
, so
apply
could be used with set-floating-point-modes
to
restore the modes in effect at the time of the call to
get-floating-point-modes
.
To make handling control of floating-point exceptions, the following macro is useful.
body
is executed with the selected floating-point exceptions
given by traps
masked out (disabled). traps
should be
a list of possible floating-point exceptions that should be ignored.
Possible values are :underflow
, :overflow
, :inexact
,
:invalid
and :divide-by-zero
.
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.
wait
instruction (x86::float-wait
) if using the lisp
conditions to catch trap within a handler-bind
. The
handler-bind
macro 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.
(floating-point-modes)
and the (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-masked
macro keeps the intervening code to
a minimum and uses only integer operations.
Previous: Floating Point Rounding Mode, Up: Floats [Contents][Index]