Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003133 [Squeak] Kernel minor always 02-27-06 12:21 07-23-06 12:49
Reporter pmm View Status public  
Assigned To MarcusDenker
Priority normal Resolution fixed  
Status closed   Product Version
Summary 0003133: [BUG][FIX] Float>>#asIEEE32BitWord and #fromIEEE32Bit:
Description Float>>#asIEEE32BitWord and #fromIEEE32Bit: converte a Float to a 32bit IEEE 754 word and vice versa.

I quote from the Float class comment (adjusted for 32bit):

sign 1 bit
exponent 8 bits with bias of 1023 (16r3FF) to produce an exponent
                    in the range -1023 .. +1024
            - 16r000:
                significand = 0: Float zero
                significand ~= 0: Denormalized number (exp = -1024, no hidden '1' bit)
            - 16r7FF:
                significand = 0: Infinity
                significand ~= 0: Not A Number (NaN) representation

Note: this implies there are two inifites and zeros (positive and negative).
However the two mentioned methods don't follow this specification. See the test changeset for examples. This is a problem for example if you put a Float in a FloatArray you might get a different Float back.
Additional Information
Attached Files  FloatBugs-pmm.1.cs [^] (1,561 bytes) 02-27-06 12:21
 FloatIEEE754Fixes-pmm.1.cs [^] (2,071 bytes) 02-27-06 12:22
 Kernel-Float-asIEEE32BitWord-Test.1.cs [^] (5,793 bytes) 05-30-06 02:29
 Kernel-Float-asIEEE32BitWord-Patch.1.cs [^] (2,248 bytes) 05-30-06 02:30
 Kernel-Float-asIEEE32BitWord-Test.2.cs [^] (8,232 bytes) 05-30-06 03:12
 Kernel-Float-asIEEE32BitWord-Patch.2.cs [^] (3,578 bytes) 05-30-06 03:12

- Relationships
related to 0004264closed  SUnit tests FloatTest>>testNaN5 and Float>>testZero2 fail 

- Notes
(0005096 - 392 - 434 - 434 - 434 - 434 - 434)
nicolas cellier
05-29-06 23:02

Good fix for converting Float nan.

However, this does not fix incorrect rounding mode.
Both new and older version incorrectly truncate toward zero.
They should honour IEEE default rounding mode (round to nearest even).
Note that FloatArrayPlugin primitiveAtPut does honour IEEE round to nearest even since it uses a simple C cast to (float).

I am preparing a test case and a patch...
 
(0005097 - 691 - 947 - 947 - 947 - 947 - 947)
nicolas cellier
05-30-06 00:04
edited on: 05-30-06 03:44

I note that gradual underflow is also broken.

How to decode 32 bits float:

number is encoded seeeeeeeemmmmmmmmmmmmmmmmmmmmmmm
1 bit sign
8 bit exponent
23 bit mantissa

sign=1 - (2rs * 2).
exponent=2reeeeeeee-127

if 2reeeeeeee is 255,
  if mmmmmmmmmmmmmmmmmmmmmmm isZero, then return Infinity*sign
  else, return NaN
elseif 2reeeeeeee is 0
  this is gradual underflow (denormalized number)
  mantissa=2r0.mmmmmmmmmmmmmmmmmmmmmmm
  exponent=exponent+1
else
  this is a normalized number
  mantissa=2r1.mmmmmmmmmmmmmmmmmmmmmmm
endif

return sign*mantissa*(1.0 timesTwoPower: exponent)

Note that IEEE 754 64bits has
1 bit sign
11 bits exponent
52 bit mantissa

 
(0005129 - 233 - 275 - 275 - 275 - 275 - 275)
nicolas cellier
05-30-06 02:41

I'm tired and want to go to bed !!!
just corrected the bug, but another related method is broken...

Float class>>#fromIEEE32Bit:
does not handle gradual underflow (denormalized numbers)

This will be my last correction tonight
 
(0006174 - 4 - 4 - 4 - 4 - 4 - 4)
MarcusDenker
07-23-06 12:49

7047
 

- Issue History
Date Modified Username Field Change
02-27-06 12:21 pmm New Issue
02-27-06 12:21 pmm File Added: FloatBugs-pmm.1.cs
02-27-06 12:22 pmm Summary [BUG] Float>>#asIEEE32BitWord and #fromIEEE32Bit: => [BUG][FIX] Float>>#asIEEE32BitWord and #fromIEEE32Bit:
02-27-06 12:22 pmm File Added: FloatIEEE754Fixes-pmm.1.cs
05-29-06 23:02 nicolas cellier Note Added: 0005096
05-30-06 00:04 nicolas cellier Note Added: 0005097
05-30-06 00:06 nicolas cellier Note Edited: 0005097
05-30-06 02:11 nicolas cellier Note Edited: 0005097
05-30-06 02:29 nicolas cellier File Added: Kernel-Float-asIEEE32BitWord-Test.1.cs
05-30-06 02:30 nicolas cellier File Added: Kernel-Float-asIEEE32BitWord-Patch.1.cs
05-30-06 02:41 nicolas cellier Note Added: 0005129
05-30-06 03:12 nicolas cellier File Added: Kernel-Float-asIEEE32BitWord-Test.2.cs
05-30-06 03:12 nicolas cellier File Added: Kernel-Float-asIEEE32BitWord-Patch.2.cs
05-30-06 03:44 nicolas cellier Note Edited: 0005097
07-15-06 11:18 MarcusDenker Relationship added related to 0004264
07-22-06 21:38 MarcusDenker Status new => resolved
07-22-06 21:38 MarcusDenker Resolution open => fixed
07-22-06 21:38 MarcusDenker Assigned To  => MarcusDenker
07-23-06 12:49 MarcusDenker Status resolved => closed
07-23-06 12:49 MarcusDenker Note Added: 0006174
07-23-06 12:49 MarcusDenker Fixed in Version  => 3.9


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
77 total queries executed.
41 unique queries executed.
Powered by Mantis Bugtracker