Decimal question and sqrt in math.h

Tim Prince tprince@computer.org
Thu Oct 25 14:54:00 GMT 2007


miha@gigabox.org wrote:

> 
> #include <stdio.h>
> #include <math.h>
> 
> int main()
> {
> printf("\n %1.55f \n", sqrt(3.9999999999999999));
> return 0;
> }
> 
> Result: 2
> 
> Why does this return 2 ??

If you meant to use long double, you should have so specified.  Decimal
digits beyond 17 aren't significant in conversion to IEEE 64-bit double.
 Some of the properties of the floating point data types are shown in
<float.h>.

Just as a matter of curiosity, how did you get this message marked as spam?



More information about the Gcc mailing list