When I do a floating point addition I get different results. My database is 32 bit Kognitio. Can some one explain me better why this is a problem when I have my floating point values well within the limits.
I do understand that the operations involving floating point numbers are not always associative due to approximation and rounding errors. But in my case, I haven't used the complete precision of storage.
Below are my trials using a simple select
Good Way!!
2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 4.90000000000000e+000
+ -9.80000000000000e+000
+ -9.80000000000000e+000
--------------------------
0.00000000000000e+000
Bad Way??
-9.80000000000000e+000
+ -9.80000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 2.45000000000000e+000
+ 4.90000000000000e+000
--------------------------
-3.55271367880050e-015
But you are using the full precision of the 32-bit floating point number. Remember that these are binary floating point values, not decimal. When you view it in decimal, you get a bunch of trailing zeros, and it looks very nice and clean. But if you were to view those values in binary, you would see a bunch of ones trailing to the right. The value in binary is not exactly equivalent to what you are seeing in decimal.
2.45 in base 10 is approximately equal to 10.011100110011001100110011001100 in 32-bit binary. (These values may not be exactly correct, but it gives the right idea.) That binary number rendered exactly in decimal is 2.449999988079071044921875, which gets rounded to 2.450000.
Adding those approximations in different orders will give different approximations.