SYSTEM WARNING: Creating default object from empty value

Mantis - Squeak
Viewing Issue Advanced Details
150 Any minor always 09-16-04 23:44 12-04-04 16:53
KenCausey  
 
normal  
closed  
fixed  
none    
none  
0000150: Number>>printShowingDecimalPlaces: output incorrect
111.2 printShowingDecimalPlaces: 2 -> '111.20'

111111111111111 printShowingDecimalPlaces: 2 -> '1.11'
123e20 printShowingDecimalPlaces: 2 -> '1.23'
10 printShowingDecimalPlaces: 20 -> Error: subscript is out of bounds: 21

Pavel
I transferred this from BFAV2 ID 24236 from a report by Pavel Krivanek <squeak1@continentalbrno.cz>
related to 0002187closed  Utilites class >> #floatPrecisionForDecimalPlaces: doesn't work for arguments bigger than 9 
related to 0001837closed  #printShowingDecimalPlaces: doesn't work for moderate or big numbers 
 PrintShowingDecimalPlacesTest-dtl.1.cs [^] (943 bytes) 11-26-04 18:26
 PrintShowingDecimalPlacesFix-dtl.1.cs [^] (1,414 bytes) 11-26-04 18:26

Notes
(0000761)
lewis   
11-26-04 18:28   
I have attached a unit test that shows the problem, and a fix to resolve it.

The fix adds a range check for Utilities>>floatPrecisionForDecimalPlaces: and a default implementation that works when the parameter is out of range.

Implementation note:
I used #caseOf:otherwise: to implement this. The result is about 25% slower than the original unchecked method. I got very slightly faster performance by writing it with a bunch of #ifTrue: lines, but I think the caseOf approach is slightly less ugly.

All other implementations that I tried (including #at:ifAbsent:, and #on:do) were significantly slower, so I settled on #caseOf:otherwise: for clarity and reasonable speed.
(0000762)
MarcusDenker   
11-26-04 18:38   
fix is attached
(0000840)
MarcusDenker   
12-04-04 16:53   
in 3.9