I have found the mismatch in the result of some complex calculations. When i thoroughly observed the intermediate results, its the std::pow function which creates that mismatch.
Below are the inputs/output.
long double dvalue = 2.7182818284589998;
long double dexp = -0.21074699576017999;
long double result = std::powl( dvalue, dexp);
64bit -> result = 0.80997896907296496 and 32bit -> result =
0.80997896907296507
I am using VS2008.
I have tried with other variation of pow function which takes long double and return long double, but still see the same difference.
double pow( double base, double exponent );
long double powl( long double base, long double exponent );
I have read some info on this:
Intel x86 processors use 80-bit extended precision internally, whereas
double is normally 64-bit wide.Different optimization levels affect
how often floating point values from CPU get saved into memory and
thus rounded from 80-bit precision to 64-bit precision. Alternatively,
use the long double type, which is normally 80-bit wide on gcc to
avoid rounding from 80-bit to 64-bit precision.
Could someone make me clearly understand the difference and ways to overcome this difference.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…