This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Decimal question and sqrt in math.h


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]