|rational to floating point? firstname.lastname@example.org (Thant Tessman) (2003-10-13)|
|Re: rational to floating point? email@example.com (Miloslav Trmac) (2003-10-13)|
|Re: rational to floating point? firstname.lastname@example.org (2003-10-13)|
|Re: rational to floating point? email@example.com (2003-10-13)|
|Re: rational to floating point? firstname.lastname@example.org (Thant Tessman) (2003-10-14)|
|Re: rational to floating point? email@example.com (Fergus Henderson) (2003-10-18)|
|Re: rational to floating point? firstname.lastname@example.org (2003-10-18)|
|Re: rational to floating point? Peter-Lawrence.Montgomery@cwi.nl (2003-10-18)|
|Re: rational to floating point? email@example.com (Thant Tessman) (2003-10-27)|
|From:||Fergus Henderson <firstname.lastname@example.org>|
|Date:||18 Oct 2003 15:27:32 -0400|
|Posted-Date:||18 Oct 2003 15:27:32 EDT|
Thant Tessman <email@example.com> writes:
>I think I have a handle on how to produce the significand and
>exponent of the floating point number (as arbitrary-precision integers
>(conveniently in base 256 in my implementation)). What's missing is
>the conversion to the actual float. The Clinger paper makes use of a
>mysteriously unexplained "make-float" function, for which there seems
>to be no portable manifestation.
The C standard provides a function ldexp() which should be helpful for
this sort of thing. Assuming you are doing this in C, here's a possible
1. Convert the significand from your arbitrary precision integer type
to a fixed precision integer type with at least as many bits as
DBL_MANT_DIG. "long long" will have enough for IEC/IEEE double
precision floating point. (The 1999 C standard requires that
"long long" be supported and have at least 64 bits. If your C compiler
doesn't support "long long" yet, complain to your C compiler vendor,
or use GNU C.)
2. Cast the significand from the fixed precision integer type to double.
Your C compiler ought to be able to do this without losing precision
(if it doesn't, complain to your C compiler vendor).
3. Convert the exponent from your arbitrary precision integer type to "int".
4. Call ldexp() with the values obtained in steps 2 and 3.
I haven't actually tried this, so I don't know whether it really works
in practice. It's possible that many C compilers might have problems
with losing precision in step 2.
Fergus Henderson <firstname.lastname@example.org> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
Return to the
Search the comp.compilers archives again.