[cmucl-imp] [cmucl-help] NaN
Marco Antoniotti
marcoxa at cs.nyu.edu
Tue Jan 10 21:30:59 UTC 2017
Since we are on the subject…
I am looking at ieeefp-tests.
The code for CMUCL (the relevant one, I assume) looks like this:
(defun make-single-float (x)
(declare (type (or (unsigned-byte 32) (signed-byte 32)) x))
(typecase x
((signed-byte 32) (kernel:make-single-float x))
(t (kernel:make-single-float (dpb x (byte 32 0) -1)))))
(defun make-double-float (x)
(declare (type (or (unsigned-byte 64) (signed-byte 64)) x))
(typecase x
((signed-byte 64) (kernel:make-double-float
(ldb (byte 32 32) x) (ldb (byte 32 0) x)))
(t (kernel:make-double-float
(dpb (ldb (byte 32 32) x) (byte 32 0) -1) (ldb (byte 32 0) x)))))
(defun single-float-bits (x)
(declare (type single-float x))
(ldb (byte 32 0) (kernel:single-float-bits x)))
(defun double-float-bits (x)
(declare (type double-float x))
(ldb (byte 64 0)
(logior (ash (kernel:double-float-high-bits x) 32)
(kernel:double-float-low-bits x))))
(defun set-floating-point-modes (&rest args &key traps accrued-exceptions
current-exceptions rounding-mode precision)
(declare (ignore traps accrued-exceptions current-exceptions rounding-mode
precision))
(apply #'ext:set-floating-point-modes args))
(defun get-floating-point-modes ()
(ext:get-floating-point-modes))
Now. I am trying to produce a version for LW that, at a minimum, implemented the following
(defun make-single-float (x)
(float x 1.0f0)) ; Would this “just work”?
(defun make-double-float (x)
(float x 1.0d0)) ; Would this “just work”?
(defun single-float-bits (x)
(declare (type single-float x))
;; Wrong for LW. No KERNEL:SINGLE-FLOAT-BITS.
(ldb (byte 32 0) (kernel:single-float-bits x)))
(defun double-float-bits (x)
(declare (type double-float x))
;; Wrong for LW. No KERNEL:DOUBLE-FLOAT-HIGH-BITS and KERNEL:DOUBLE-FLOAT-LOW-BITS.
(ldb (byte 64 0)
(logior (ash (kernel:double-float-high-bits x) 32)
(kernel:double-float-low-bits x))))
What do the two missing function actually do? Sorry. I tried to read the sources, but (1) I am too lazy and (2) I am way too rusty in deep lisping (cfr., functions that just call themselves :) )
Do they just get the actual bitwise representation of the floats assuming a Lisp representation?
Cheers
—
MA
> On Jan 10, 2017, at 21:42 , Marco Antoniotti <marcoxa at cs.nyu.edu> wrote:
>
>
>> On Jan 10, 2017, at 16:46 , Raymond Toy <toy.raymond at gmail.com> wrote:
> ...
>>
>> Marco> Well. I have been fooling around (read: veered off a
>> Marco> tangent) with interval arithmetic, where it looks like you
>> Marco> need to ensure that your rounding modes are set to positive
>> Marco> or negative infinity when using an end points
>> Marco> representation. That’s were it all started.
>>
>> That's one way. I vaguely recall some Fortran TOMS package that
>> included interval arithmetic, but I think it just did something simple
>> like multiply by 1+e for some tiny e.
>>
>> Setting the rounding modes twice (up and down) for every operation is
>> pretty expensive.
>
> Ok. I presume that the references talk of rounding modes only because they assume some “very-close-to-the-metal” implementation.
>
> In any case, the need for NaNs and infinities is there. And right now CL is lacking in this respect.
>
> Cheers
>
> --
> Marco Antoniotti
>
>
> _______________________________________________
> cmucl-imp mailing list
> cmucl-imp at lists.zs64.net
> https://lists.zs64.net/mailman/listinfo/cmucl-imp
--
Marco Antoniotti
More information about the cmucl-imp
mailing list