[cmucl-imp] [cmucl-help] NaN
Stelian Ionescu
sionescu at cddr.org
Tue Jan 10 23:37:14 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-single-float (x)
(declare (type (or (unsigned-byte 32) (signed-byte 32)) x))
(cffi:with-foreign-object (p :uint32)
(setf (cffi:mem-ref p :uint32) x)
(cffi:mem-ref p :float)))
Definitely portable across Lisps and probably across CPUs. If you don't care about the former, use LW's own FFI.
--
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
More information about the cmucl-imp
mailing list