[Openmcl-devel] Printing/Reading floats
Raymond Wiker
Raymond.Wiker at fast.no
Mon Mar 17 09:32:09 PST 2003
Christophe Rhodes writes:
> 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...
How about
(defun hypothetical-integer-encode-float (sig exp sign)
(* sign (scale-float (float sig) exp)))
(Actually, I just tried this, in SBCL, with pi - didn't look
to good :-)
BTW: In Henry Baker's "Pragmatic Parsing" paper there is a
reference to a paper by William Clinger:
Clinger, William D. "How to Read Floating Point Numbers Accurately".
ACM PLDI'90. Sigplan Not. 25,6 (June 1990), 92-101
--
Raymond Wiker Mail: Raymond.Wiker at fast.no
Senior Software Engineer Web: http://www.fast.no/
Fast Search & Transfer ASA Phone: +47 23 01 11 60
P.O. Box 1677 Vika Fax: +47 35 54 87 99
NO-0120 Oslo, NORWAY Mob: +47 48 01 11 60
Try FAST Search: http://alltheweb.com/
_______________________________________________
Openmcl-devel mailing list
Openmcl-devel at clozure.com
http://clozure.com/cgi-bin/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list