Floating point differences between Java 1.5 and Java 6

Hi all.

One of our unit tests started failing on introduction of Java 6, and it turns out that the operations in question are floating point operations. We're performing some floating point math on pixel values for an image, and depending on the JRE version, a different result is generated.

In addition to this, the floating point maths runs around 100 times faster under Java 6. I'm not exaggerating -- the Java 1.5 version runs in 2.5 seconds on average, and the Java 6 version runs in 25 milliseconds on average.

I can't see anything explicitly in the release notes which says that floating point has significantly changed, but has anyone else noticed similar occurrences since the upgrade?

[722 byte] By [trejkaza] at [2007-11-26 13:14:03]
# 1

Hi,

I haven't used Java 6 yet, so I don't know about the performance improvements, but I don't find it strange.

Calculations using floating points can give different results in different VM versions and on different platforms. You should declare the class to use strictfp if you want to get the same result on all implementations (that is of course slower)

http://en.wikipedia.org/wiki/Strictfp

Kaj

kajbja at 2007-7-7 17:32:58 > top of Java-index,Java Essentials,Java Programming...
# 2
I think what I might do is just rewrite the maths to use integer maths. That will speed it up again anyway, and since we only care about precision to 4 decimal points it shouldn't be too hard to do (will just multiply all sides by 10000.)
trejkaza at 2007-7-7 17:32:58 > top of Java-index,Java Essentials,Java Programming...
# 3
While I don't know of a change that this can be attributed to, there was a fairly extensive reworking of the maths libs to add new methods ( http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4406429 ) and I wouldn't be surprised to find that this is the cause.
ChuckBinga at 2007-7-7 17:32:58 > top of Java-index,Java Essentials,Java Programming...