toString-ing floats and doubles
sballard at netreach.net
Wed Jun 28 11:54:51 PDT 2000
Archie Cobbs wrote:
> * The conversion of floats or doubles to strings does not completely
> conform to Sun's spec. For example, Double.toString() will display
> the double 0x400B333333333333 as "3.3999999999999999" instead of "3.4".
> If you would like to work on improving this code that would be
> warmly encouraged.
Hmm. Well, the intricacies of IEEE floating point are a bit beyond me at
this point, but after looking at the implementations in Kaffe, Classpath
and libgcj, libgcj's looks like it might be interesting. I can't tell
you whether or not it gives the right answer for all cases, but it is
implemented from scratch rather than using printf, so it seems there
might be a good chance. It will obviously need some changes - libgcj
doesn't use JNI, for a start. But here's a URL into their cvsweb...
Note: libgcj is under the GPL with an exception clause; it's certainly
compatible with Kaffe's GPL. As of a few months ago, I believe the
copyright is held by the FSF.
More information about the kaffe