Decimal question and sqrt in math.h
miha@gigabox.org
miha@gigabox.org
Thu Oct 25 10:19:00 GMT 2007
I use Gentoo Linux, Gcc 4.1.1 and Intel Celeron processor.
I compiled this file:
#include <stdio.h>
#include <math.h>
int main()
{
printf("\n %1.55f \n", sqrt(3.999999999999999));
return 0;
}
I get 1.999999999999999777955395074968691915273666381835 9375000
If you add one more 9 to sqrt you get 2.
#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 ??
Miha Svalina
More information about the Gcc
mailing list