Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication
Richard Henderson
rth@redhat.com
Fri Oct 8 00:17:00 GMT 2004
On Thu, Oct 07, 2004 at 11:18:34PM +0000, Joseph S. Myers wrote:
> I can't find a reference to this discussion right now and I think it must
> have been some other rounding mode, but the idea was that half the
> smallest floating point value rounded to the same value but a quarter of
> it rounded to zero
I modified my test program to iterate through all of the rounding
modes, and still couldn't find such a case.
For the record, and in case someone can identify a bug that would
have caused this case to be missed, the test program follows. I
ran the test program on ia64 to avoid any possibility of mucking
up with extended precision on x86.
r~
#include <fenv.h>
#define hide(x) \
({ __typeof (x) x_ = (x); asm ("" : "=frg"(x_) : "0"(x_)); x_; })
void test(void)
{
int i;
union {
float f;
int i;
} u;
for (i = 0; i < 1<<24; i++)
{
float f, t0, t1, t2;
u.i = i;
f = u.f;
t0 = hide(f * 0.5f);
t1 = hide(t0 * 0.5f);
t2 = hide(f * 0.25f);
if (t1 != t2)
{
printf ("%.10a: %.10a != %.10a\n", f, t1, t2);
abort ();
}
}
}
int main()
{
int r;
for (r = 0; r < 4; ++r)
{
int m;
switch (r)
{
case 0:
m = FE_TOWARDZERO;
break;
case 1:
m = FE_DOWNWARD;
break;
case 2:
m = FE_TONEAREST;
break;
case 3:
m = FE_UPWARD;
break;
}
fesetround (m);
test ();
}
return 0;
}
More information about the Gcc-patches
mailing list