floating point - Can equivalent expressions yield different float results? -


the discussion this answer got me thinking equality , equivalence of floating point numbers. aware floating point numbers can not represented accurately. question is, there mathematically equivalent expressions yield different results when using floating point arithmetic? can provide example?

edit: let me more clear. aware same code different compilers or different machines can return different results. looking 2 mathematically equivalent expressions can compare in python interpreter/c++ program/whatever , unexpected result.

are there mathematically equivalent expressions yield different results when using floating point arithmetic?

absolutely. in fact, should expect happen more not.

even same code can yield different results on different machines or compilers.

can provide example?

sure. java code should repeatably yield 2 different results:

public strictfp class test {     public static void main(string[] args) throws exception {         float = 0.7f;         float b = 0.3f;         float c = 0.1f;          float r1 = ((a * b) * c);         float r2 = (a * (b * c));          system.out.println(r1);         system.out.println(r2);     } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -