Bug 23466 - call to _dtoa is possibly incorrect
Summary: call to _dtoa is possibly incorrect
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-18 17:30 UTC by Ronald Veldema
Modified: 2016-09-30 22:55 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-18 22:18:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Veldema 2005-08-18 17:30:14 UTC
Tried with gcj 4/3.4 and own compiler with classpath from CVS:
Double.toString() gives wrong answer for some inputs.
Example:
--------------[input]----------
class hi {
    static double a = 0.0010;
    public static void main(String args[]) {
	System.out.println("hi:" + a);
    }
}
-----------[outputs]--------------
veldema@faui21e:~/tests> javac hi.java
veldema@faui21e:~/tests> java hi
hi:0.0010
veldema@faui21e:~/tests> gcj hi.java --main=hi
veldema@faui21e:~/tests> ./a.out
hi:0.001

-----------[ problem ]-----------------
The problematic code is in _dtoa somewhere.
Also, shouldn't the call to _dtoa be:

  _dtoa (value, 0, (isFloat ? 20 : 1), &decpt, &sign, NULL, buffer, (int) isFloat);

???
Comment 1 Andrew Pinski 2005-08-18 22:18:45 UTC
This is libgcj issue only.

Confirmed.
Comment 2 Dalibor Topic 2005-08-18 22:41:03 UTC
that looks like a bug in Sun's implementation, as the Double.toString() API
specs demand that Double.toString returns only as many digits as necessary to
uniquely identify the floating point number. 

Adding one or more '0' digits does not seem useful, as 0.001 and 0.0010 are
mathematically speaking the same number. It would in fact seem to violate the
API specifications.

cheers,
dalibor topic
Comment 3 Tom Tromey 2005-08-19 16:20:17 UTC
I agree that this is most likely not a libgcj bug.
Ronald, why do you think the _dtoa call ought to be changed?
Comment 4 Ronald Veldema 2005-08-22 12:03:27 UTC
1) I will file a bug report with SUN and see what they say and report back here
2) I read the comments with _dtoa and for floats the arg is interpretted as
single-precision if mode >= 16 (seems for a double you both need to pass the
isfloat = false && mode == 20
R.
Comment 5 Ronald Veldema 2005-08-22 12:18:47 UTC
Confirmed, this is a bug in SUN's JDK since 2001.
Perhaps a a bug should be introduced to make libgcj/classpath bug compatible ?
if (double_string == "0.00x" && x != '0') return return "0.00x0" 
should do the trick.
Ronald.
Comment 6 Dalibor Topic 2005-08-22 13:25:18 UTC
It seems to be clearly a bug in how some non-free implementation implements the
specifications.

Since Sun Microsystems has confirmed the bug in their implementation, and the
specification is clear on the matter, I don't think it makes sense to make GNU
Classpath less compatible.

Unless Sun has decided to ammend the API specification, I think this bug should
be closed and marked "invalid".

cheers,
dalibor topic
Comment 7 Tom Tromey 2005-08-22 15:00:01 UTC
I would prefer to leave the PR open to address the _dtoa issue.
I've updated the PR synopsis to reflect this.
I agree that we should not change our toString output, as ours is
correct.
Comment 8 Andrew Pinski 2016-09-30 22:55:48 UTC
Closing as won't fix as libgcj (and the java front-end) has been removed from the trunk.