CBFalconer said:
I am saying that, if defined to the weight of the LSB in float.h,
the system is WRONG.
No, in that case YOU are WRONG. The definition of xxx_EPSILON at the
bottom of page 26 of n1256 is:
| the difference between 1 and the least value greater than 1 that is
| representable in the given floating point type, b**(1−p)
^^^^^^^^^^^^^
If you have problems with the English then read the simple equation at
the end.
The definitions of b and p (given earier in that section) are:
b base or radix of exponent representation (an integer > 1)
p precision (the number of base-b digits in the signiï¬cand)
I'm sure that you have been shown this definition before.
Oh, and if the maths is a problem read the words. Note the word
"representable". That means that 1.0+xxx_EPSILON is ALWAYS a
representable number, which means that it exactly corresponds to a bit
pattern, so xxx_EPSILON CANNOT be smaller than the value represented by
one bit.
Note the results of the following as well:
#include <float.h>
#include <fenv.h>
#include <math.h>
#include <stdio.h>
void check(double one,double eps)
{
double pluseps = one+eps;
double next = nextafter(one,2.0);
double plushalf = one + eps/2.0;
printf("Rounding mode: %d\n",fegetround());
if (next==pluseps)
printf("Epsilon is one bit at 1.0, 1.0=%a, pluseps=%a, next=%a,
plushalf=%a, DBL_EPSILON=%a\n",1.0,pluseps,next,plushalf,DBL_EPSILON);
else
puts("Oops");
}
int main(void)
{
check(1.0,DBL_EPSILON);
fesetround(FE_DOWNWARD);
check(1.0,DBL_EPSILON);
fesetround(FE_TONEAREST);
check(1.0,DBL_EPSILON);
fesetround(FE_TOWARDZERO);
check(1.0,DBL_EPSILON);
fesetround(FE_UPWARD);
check(1.0,DBL_EPSILON);
}
Mark-Gordons-MacBook-Air:~ markg$ gcc -std=c99 -pedantic -lm -Wall
-Wextra t.c
Mark-Gordons-MacBook-Air:~ markg$ ./a.out
Rounding mode: 0
Epsilon is one bit at 1.0, 1.0=0x1p+0, pluseps=0x1.0000000000001p+0,
next=0x1.0000000000001p+0, plushalf=0x1p+0, DBL_EPSILON=0x1p-52
Rounding mode: 1024
Epsilon is one bit at 1.0, 1.0=0x1p+0, pluseps=0x1.0000000000001p+0,
next=0x1.0000000000001p+0, plushalf=0x1p+0, DBL_EPSILON=0x1p-52
Rounding mode: 0
Epsilon is one bit at 1.0, 1.0=0x1p+0, pluseps=0x1.0000000000001p+0,
next=0x1.0000000000001p+0, plushalf=0x1p+0, DBL_EPSILON=0x1p-52
Rounding mode: 3072
Epsilon is one bit at 1.0, 1.0=0x1p+0, pluseps=0x1.0000000000001p+0,
next=0x1.0000000000001p+0, plushalf=0x1p+0, DBL_EPSILON=0x1p-52
Rounding mode: 2048
Epsilon is one bit at 1.0, 1.0=0x1p+0, pluseps=0x1.0000000000001p+0,
next=0x1.0000000000001p+0, plushalf=0x1.0000000000001p+0,
DBL_EPSILON=0x1p-52
Mark-Gordons-MacBook-Air:~ markg$
This is on an Intel platform in x86 (32 bit) mode, so can check the
details of floating point. Note that 1+DBL_EPSILON is not affexted by
rounding mode, but smaller values are (as per the standard).