[Openmcl-devel] Printing/Reading floats

Christophe Rhodes csr21 at cam.ac.uk
Mon Mar 17 09:15:32 PST 2003

Gary Byers <gb at clozure.com> writes:

> I can't think of a more portable way to read/write floats in CL: if
> there's a CL function that does the inverse of INTEGER-DECODE-FLOAT,
> I can't remember what it's called.
> ? (multiple-value-call #'hypothetical-integer-encode-float
>      (integer-decode-float f))
> would (hypothetically) be guaranteed to be EQL to f (at least for
> normalized cases) and the integer triples could be read/written
> accurately.

IANAFPExpert, but would

(defun hypothetical-integer-encode-float (sig exp sign)
  (float (* sign (/ sig (expt 2 exp)))))

be close?  Obviously there are issues wrt single/doubleness, but...


http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)

Openmcl-devel mailing list
Openmcl-devel at clozure.com

More information about the Openmcl-devel mailing list