Dear all,
I'm using the math function sqrt from math.h with long double variables and found out, that mbed calculated sqrt(2) = 1,41421354 (C-codeline is: "x = (long double) sqrt((float)x);" where x is defined as long double). I inserted the type conversions due to the fact that sqrt is defined as float according to the C book I'm using (Herbert Schildt "C++ from the ground up"). If you insert the result into the formula 1,41421354 * 1,41421354 you'll get 1,99999993 as result. I used lcd.printf ("%# 1.8Lf,x); for the output. Using "%# 1.10Lf" as format string wasn't that much better. The HP Smartcalc 300 calculates sqrt(2) = 1,414213562 and 1,414213562 * 1,414213562 = 2,000000000.
Am I making a mistake here or is there an alternative math library with higher accuracy ?
Thanks for any hint in advance.
Regards
Karl
Dear all,
I'm using the math function sqrt from math.h with long double variables and found out, that mbed calculated sqrt(2) = 1,41421354 (C-codeline is: "x = (long double) sqrt((float)x);" where x is defined as long double). I inserted the type conversions due to the fact that sqrt is defined as float according to the C book I'm using (Herbert Schildt "C++ from the ground up"). If you insert the result into the formula 1,41421354 * 1,41421354 you'll get 1,99999993 as result. I used lcd.printf ("%# 1.8Lf,x); for the output. Using "%# 1.10Lf" as format string wasn't that much better. The HP Smartcalc 300 calculates sqrt(2) = 1,414213562 and 1,414213562 * 1,414213562 = 2,000000000.
Am I making a mistake here or is there an alternative math library with higher accuracy ?
Thanks for any hint in advance.
Regards
Karl