not at the time, I merely thought of it as an interesting occurrence and
worked around it.
I would have to find an example of it again...
I remember seeing the problem a few years ago in some code of mine, but
don't have any recent memory of bugs resulting from it (but, then again,
this could also be due to code paranoia...).
just went and tried to recreate it, with mixed results:
a raw conversion does not show any issues (seems to always be reliable);
if I add a value to the double, and subtract the same value, then it
starts acting up.
testing the code below in Fedora 13 x86-64 within VMware (yes, not the
raw HW, but I would otherwise have to reboot).
#include <stdio.h>
int main()
{
double d;
int i, j, k;
for(i=0; i<100000000; i++)
{
j=rand()*rand()*i;
d=j;
d=d+1.0; //(1)
d=d-1.0; //(1)
k=d; //(2)
k=(d>=0?(int)(d+0.0001)
int)(d-0.0001)); //(2)
if(j!=k)
printf("%d %d\n", j, k);
}
}
1: if these lines are commented out, then the printf is never called,
but if uncommented (along with using different constant values), then I
start seeing messages (with it off-by-one, rounded towards 0).
2: if I switch to the second form, which makes the fudging, then the
messages disappear (they still appear with the first form).
so, it would seem to be mostly an issue in this case of whether or not
one does any arithmetic on the values (not sure whether or not this
still counts). CPU is an "AMD Athlon II X4 630".
or, at least, this is what I am seeing here...