1. Re: Peculiar IEEE Bug...
"Carl R. White" <C.R.White at SCM.BRAD.AC.UK> wrote:
>I don't know whether the following applies to the new v2.1...
>
>I was messing around with [my] mathbag.e last night, and discovered
>something interesting:
>
>atom ieee
>ieee = -1e-308
>? ieee < 0
>? ieee = 0
>? ieee > 0
>
>Result when run:
>0
>0
>1
>
>Should have returned:
>1
>0
>0
>
>Something funny going on here...
>This also applies to -2e-308. -3e-308 works right. (So I'm using it. :) )
>
>Is it the Interpreter, Watcom C, the IEEE standard, or is my PII-233
>playing up? /me looks worried about the latter...
I ran this both under PD v2.1alpha and my registered v1.4a. (Yes, I'm
eventually getting around to purchasing the next registered version...) In
both cases, it turned up results identical to yours -- -1e-308 and -2e-308
came out being greater than zero, while -3e-308 came out less than.
Just for kicks, I tried defining the value in terms of multiplication --
such as 2e-154 * -1e-154 and so forth. It made no difference how the number
was defined -- in every instance, the final values -1e-308 and -2e-308 came
out greater than zero, while -3e-308 came out less than.
I then did some further tests to find the exact pivot point. It turns out
that the atom -2.225073858507202e-308 is correctly evaluated as less than
zero, while -2.225073858507200e-308 somehow comes out *greater* than zero.
So the pivot point is somewhere around these two values.
To further investigate, I decided to use the handy atom_to_float64()
function to convert these values into their IEEE byte-representation values,
to see what was going on "behind the scenes". It turns out that our
"correct" value (-2.225073858507202e-308) is represented internally as
{0,0,0,0,0,0,16,128}, while our "incorrect" value (-2.225073858507200e-308)
is represented internally as {253,255,255,255,255,255,15,128}!!!
Now, I don't know anything about the IEEE standards at work here, but this
seems rather fishy to me. I used the float64_to_atom() function to convert
these sequences back into atoms -- just to see if they were converting
correctly -- and I got the exact same values that I put in. So it's not a
conversion error -- apparently, that's the way these values are actually
represented internally. Weird.
So, I'd say it's an IEEE thing.
Gabriel Boehme
P.S. Can anyone tell me where I can find documentation for the IEEE
standards at work here? I'm curious now...