Concerning the library fenv.h in C, I have some difficulties to understand what the rounding direction mode does when using fesetround() and the direction FE_TONEAREST (default) in particular.
There are 4 types of rounding directions in the library :
- FE_TONEAREST
- FE_UPWARD
- FE_DOWNWARD
- FE_TOWARDZERO
On doubles :
double res = 0.14*50;
printf ("res = %.50lf \n",res);
This returns : res = 7.00000000000000088817841970012523233890533447265625
(the compiler says that res > 7)
However, on floats :
float res = 0.14*50;
printf ("res = %.50f \n",res);
returns 7.00000000000000000000000000000000000000000000000000
(res = 7)
On long doubles :
long double a;
long double b;
scanf("%Lf",&a);
scanf("%Lf",&b);
long double res = a*b;
printf("%.50Lf \n",res);
returns 7.00000000000000000000000000000000000000000000000000
(res = 7)
Is the double type more risky for floating point arithmetics on the FE_TONEAREST mode ?