Add with-float-rounding-mode macro
Describe the feature
Add with-float-rounding-mode
macro to wrap around code that is run with
the rounding mode set to the value provided.
Is there a prototype?
Here is a very rough sketch that kind of lays out the design. This is untested.
(defmacro with-float-rounding-mode (mode &body)
`(let ((modes (get-floating-point-modes)))
(unwind-protect
(progn
(set-floating-point-modes :rounding-mode ,mode)
,@body)
(apply 'set-floating-point-modes modes))))
where mode
is one of the keywords allowed by
set-floating-point-modes
for the rounding mode.
Ideally, this macro would diddle the FP control word directly instead of using set-floating-point-modes
. Also, we wouldn't completely restore the FP modes but only restore the rounding mode.
Describe the feature in more detail
We already provide with-float-traps-masked
and
with-float-traps-enabled
. It makes sense to have a corresponding
with-float-rounding-mode
too.