Float>>#asIEEE32BitWord

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Float>>#asIEEE32BitWord

Philippe Marschall
Hi

I think Float>>#asIEEE32BitWord is bugged for NaNs. Why?
Float nan asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2
yields: '01111111100000000000000000000000'
which is excately the same as
Float infinity asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2

so basically
sign: 0
exponent: 255
mantissa: 0

According to the class comment of Float and Google this is the correct
representation of positive inifinity. A NaN would have a non-zero
mantissa.

I think the bug is:
        exponent > 254 ifTrue:["Overflow"
                exponent := 255.
                mantissa := 0].
this should be:
        exponent > 254 ifTrue:["Overflow"
                exponent := 255.
                self isNaN ifFalse: [
                        mantissa := 0 ]  ].

Does this make any sense?

Cheers
Philippe

Reply | Threaded
Open this post in threaded view
|

Re: Float>>#asIEEE32BitWord

Philippe Marschall
> I think Float>>#asIEEE32BitWord is bugged for NaNs. Why?
> Float nan asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2
> yields: '01111111100000000000000000000000'
> which is excately the same as
> Float infinity asIEEE32BitWord printPaddedWith: $0 to: 32 base: 2
>
> so basically
> sign: 0
> exponent: 255
> mantissa: 0
>
> According to the class comment of Float and Google this is the correct
> representation of positive inifinity. A NaN would have a non-zero
> mantissa.
>
> I think the bug is:
>         exponent > 254 ifTrue:["Overflow"
>                 exponent := 255.
>                 mantissa := 0].
> this should be:
>         exponent > 254 ifTrue:["Overflow"
>                 exponent := 255.
>                 self isNaN ifFalse: [
>                         mantissa := 0 ]  ].
>
> Does this make any sense?

Well of course this wasn't the only bug.

Float fromIEEE32Bit: 16r80000000 returns 0.0 instead of Float negativeZero
Float negativeZero asIEEE32BitWord returns 0 instead of 16r80000000.

Philippe