Previous: , Up: Floats   [Contents][Index] Accessing the Floating Point Modes

These functions can be used to modify or read the floating point modes:

Function: extensions:set-floating-point-modes &key :traps :rounding-mode :fast-mode :accrued-exceptions :current-exceptions
Function: extensions:get-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 :underflow, :overflow, :inexact, :invalid and :divide-by-zero. Initially all traps except :inexact are enabled. See float-traps.


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.


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.

Macro: ext:with-float-traps-masked traps &body body

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:

Previous: , Up: Floats   [Contents][Index]