libgcj/10632: Numerical result differs from Sun JDK

jens.mueller@ira.uka.de jens.mueller@ira.uka.de
Mon May 5 21:36:00 GMT 2003


>Number:         10632
>Category:       libgcj
>Synopsis:       Numerical result differs from Sun JDK
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 05 21:36:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     jens.mueller@ira.uka.de
>Release:        unknown-1.0
>Organization:
>Environment:

>Description:
Please look at the file.

I compiled it with java from Sun (Blackdown) JDK 1.4.1, and ran it
with java from the same package:

jens@debian:~/studium/semester2/info2/ue1java$ java PiApproximationRecursive 20000
3.1415426535898248
Approximierter Wert für pi: 3.1415426535898248


I also compiled it with
gcj --main=PiApproximationRecursive PiApproximationRecursive.java

I got this result:

jens@debian:~/studium/semester2/info2/ue1java$ ./a.out 20000
3.1415426535898208
Approximierter Wert für pi: 3.1415426535898208


I think that the Java Language Standard clearly specifies the order in
which expressions are evaluated. The result of a single floating point
operation is specified in the respective IEEE standards.

So either gcj's or JDK's behavior is broken here ...

I suppose the former.


P.S.: Compiling to a .class file with gcj-wrapper-3.2 and
running with gij (3.0, in that case) gives yet another result ...


-- System Information
Debian Release: testing/unstable
Kernel Version: Linux debian 2.4.20-k7 #1 Tue Jan 14 00:29:06 EST 2003 i686 unknown unknown GNU/Linux

Versions of the packages gcj-3.2 depends on:
ii  gcc-3.2        3.2.3-0pre9    The GNU C compiler
ii  gcc-3.2-base   3.2.3-0pre9    The GNU Compiler Collection (base package)
ii  java-common    0.19           Base of all Java packages
ii  libc6          2.3.1-16       GNU C Library: Shared libraries and Timezone
ii  libgcj3        3.2.3-0pre9    Java runtime library for use with gcj
ii  libgcj3-dev    3.2.3-0pre9    Java development headers and static library 
ii  zlib1g         1.1.4-11       compression library - runtime
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-java; name="PiApproximationRecursive.java"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="PiApproximationRecursive.java"

LyoqCiAqIEBhdXRob3IgSmVucyBN/GxsZXIKICoKICovCi8qCiAqIENyZWF0ZWQgb24gMDUuMDUu
MjAwMwogKgogKi8KCi8qKgogKiBAYXV0aG9yIEplbnMgTfxsbGVyCiAqCiAqLwpwdWJsaWMgY2xh
c3MgUGlBcHByb3hpbWF0aW9uUmVjdXJzaXZlIHsKICAgIC8qKgogICAgICogVGhpcyB2YXJpYWJs
ZSBzcGVjaWZpZXMgdGhlIGRlZmF1bHQgbnVtYmVyIG9mIHJlY3Vyc2lvbiBzdGVwcywgaWYgbm9u
ZSB3YXMgZ2l2ZW4gb24gdGhlCiAgICAgKiBjb21tYW5kIGxpbmUuCiAgICAgKi8KICAgIHB1Ymxp
YyBzdGF0aWMgaW50IERlZmF1bHROdW1iZXJPZlJlY3Vyc2lvblN0ZXBzID0gMTAwMDsKCiAgICAv
KioKICAgICAqIEBwYXJhbSBudW1iZXJPZlN0ZXBzIE51bWJlciBvZiBzdGVwcyBmb3IgYXBwcm94
aW1hdGlvbi4KICAgICAqIEByZXR1cm4gVGhlIGFwcHJveGltYXRlZCB2YWx1ZSBvZiB0aGUgbnVt
YmVyIHBpLgogICAgICovCiAgICBwdWJsaWMgc3RhdGljIGRvdWJsZSBjYWxjdWxhdGVQaShpbnQg
bnVtYmVyT2ZTdGVwcykgewogICAgICAgIHJldHVybiA0ICogKGRvUG9zaXRpdmVSZWN1cnNpb25T
dGVwKDAsIDEsIG51bWJlck9mU3RlcHMpKTsKICAgIH0KCiAgIAogICAgcHJpdmF0ZSBzdGF0aWMg
ZG91YmxlIGRvUG9zaXRpdmVSZWN1cnNpb25TdGVwKAogICAgICAgIGRvdWJsZSBjdXJyZW50VmFs
dWUsCiAgICAgICAgaW50IGN1cnJlbnREaXZpc29yLAogICAgICAgIGludCBzdGVwc1RvR28pIHsK
ICAgICAgICBpZiAoc3RlcHN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lcndpc2UsIHRo
ZSBkZWZhdWx0IHZhbHVlIGlzIDIwMDAuCiAgICAgICogCiAgICAgICovCgogICAgcHVibGljIHN0
YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIGludCBudW1iZXJPZlJlY3Vy
c2lvbnMgPSBEZWZhdWx0TnVtYmVyT2ZSZWN1cnNpb25TdGVwczsKICAgICAgICBpZiAoYXJncy5s
ZW5ndGggPj0gMSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbnVtYmVyT2ZS
ZWN1cnNpb25zID0gSW50ZWdlci5wYXJzZUludChhcmdzWzBdKTsKICAgICAgICAgICAgfSBjYXRj
aCAoTnVtYmVyRm9ybWF0RXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgICAgIC8vIGRvIG5vdGhp
bmcsIGtlZXAgZGVmYXVsdCB2YWx1ZQogICAgICAgICAgICB9CiAgICAgICAgICAgIGRvdWJsZSBw
aSA9IGNhbGN1bGF0ZVBpKG51bWJlck9mUmVjdXJzaW9ucyk7CiAgICAgICAgICAgIFN5c3RlbS5v
dXQucHJpbnRsbihwaSk7CiAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQXBwcm94aW1p
ZXJ0ZXIgV2VydCBm/HIgcGk6ICIrcGkpOwogICAgICAgIH0KICAgIH0KfQo=



More information about the Java-prs mailing list