#### Important changes to forums and questions

All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.

## Accuracy of math.h functions

**.**

**2 replies**

All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.

Topic last updated 29 Dec 2011, by ** **.
**
2
replies
**

You do not have the correct permissions to perform this operation. Please, contact us at support@mbed.com to gain full access.

×
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