Manan wrote:
Below is the part of code in which i am seeing this behaviour. Red line is the exact line which gives different results with and without optimization.
What red line?
The value of x[i] at that point is 1.5(exact) value of box_xh is 2.1 and rnx is 0.6 so icelx should evaluate to 6. which it does if i dont use optimization but when i switch optimization it gives icelx = 5. which is not correct.
So can some please tell me what i am doing wrong in this code.
You are presuming that the computer represents decimal floating point values exactly. Refer to
What Every Computer Scientist Should Know about Floating-Point Arithmetic by David Goldberg, including Doug Priest's supplement (PDF format)
linked to from the gcc 'further readings' page.
nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@xxxxxxxxxxxxxxxx :: http://www.planetfall.pwp.blueyonder.co.uk