Floating point bug? Or Feature?
- From: "Tim Mensch" <tim-usenet-4567@xxxxxxxxxxx>
- Date: Fri, 07 Mar 2008 18:59:56 -0600
Can someone tell me why this isn't a bug?
double foo = INT_MAX ;
double bar = 0 ;
double bax = foo + bar ;
ASSERT(foo==INT_MAX); // This succeeds; easily enough precision to hold 2^31
ASSERT(bax==INT_MAX); // This fails!? INT_MAX+0 == INT_MAX+1!?
I built this on Visual C++ 2005 with /fp=precision ("precision" floating point). It created very simple floating point assembly language (this is from a debug build, but it fails in debug and release):
double foo = INT_MAX ;
00513C21 fld qword ptr [__real@41dfffffffc00000 (576208h)]
00513C27 fstp qword ptr [ebp-48h]
double bar = 0 ;
00513C2A fldz
00513C2C fstp qword ptr [ebp-58h]
double bax = foo + bar ;
00513C2F fld qword ptr [ebp-48h]
00513C32 fadd qword ptr [ebp-58h]
00513C35 fstp qword ptr [ebp-68h]
Sure enough, when the fadd is executed, the stack floating point value goes from INT_MAX to INT_MAX+1, even though it's adding a zero. This happens on both an Intel Pentium Core2Duo and an AMD Turion64 (running in 32-bit mode).
Please CC my email address when replying, or it may take me a while to notice. Yes, it's a real address as-is, at least for now--if it ends up blocked in the future, or I don't reply to it, then change the number and it will work again. :)
Thanks in advance!
Tim Mensch
.
- Follow-Ups:
- Re: Floating point bug? Or Feature?
- From: Tim Mensch
- Re: Floating point bug? Or Feature?
- From: purnnamu
- Re: Floating point bug? Or Feature?
- From: purnnamu
- Re: Floating point bug? Or Feature?
- From: Quadibloc
- Re: Floating point bug? Or Feature?
- From: glen herrmannsfeldt
- Re: Floating point bug? Or Feature?
- Next by Date: Re: Floating point bug? Or Feature?
- Next by thread: Re: Floating point bug? Or Feature?
- Index(es):
Relevant Pages
|
|