SYSTEM WARNING: Creating default object from empty value

Mantis - Squeak
Viewing Issue Advanced Details
5640 Kernel minor always 12-15-06 06:33 04-18-10 22:04
nicolas cellier  
closed 3.9  
none trunk  
0005640: additional tests and fixes for Number>>printShowingDecimalPlaces:
I noticed three problems with Number>>printShowingDecimalPlaces:

 1. the leading minus sign was missing for negative numbers between 0 and -1,
 2. rounding was screwy for both negative and positive numbers,
 3. the category of the method is 'converting' but should be 'printing'.
I have added several tests to NumberTest>>testPrintShowingDecimalPlaces to
illustrate the problems. I included a test for the category in the
tests and changed the category from 'converting' to 'printing' (but
left it commented out? Feel free to email me to explain what I should have
done if different -- />
Then, I modified Number>>printShowingDecimalPlaces: so the old and the new tests of NumberTest pass.
In particular,

     -0.98 printShowingDecimalPlaces: 2

fails to show the minus sign, and

     2.567 printShowingDecimalPlaces: 2

answers '2.56' but should answer '2.57'.

The new version of #printShowingDecimalPlaces attached fixes those problems and still passes the other NumberTest tests.

related to 0007134closed andreas Float rounded is inexact 
related to 0007028closed nicolas cellier printShowingDecimalPlaces: is broken in 3.10 
related to 0007372closed nicolas cellier printShowingDecimalPlaces: justify fraction to the #right instead of the #left 
 fcsPrintShowingDecimals.cs.gz [^] (1,243 bytes) 12-15-06 06:33
 fcsNumberPrintShowingDecimals.3.cs.gz [^] (1,419 bytes) 02-14-07 21:55
 Number-printShowingDecimalPlace-Test-M5640-nice.1.cs [^] (1,379 bytes) 03-24-08 16:10
 Number-printShowingDecimalPlace-Patch-M5640-nice.1.cs [^] (2,667 bytes) 03-24-08 16:11
 Number-printShowingDecimalPlace-Patch-M5640-nice.2.cs [^] (2,667 bytes) 04-23-08 22:43
 Number-printShowingDecimalPlace-Test-M5640-nice.2.cs [^] (1,882 bytes) 04-23-08 23:01

02-14-07 22:00   
Scott Wallace pointed out that the version of #printShowingDecimalPlaces: in fcsPrintShowingDecimals.cs.gz (15 Dec 2006) fails in cases such as
   '0.01' printShowingDecimalPlaces: 2

I added an additional test for that and also a test for the case where the sign of the result should be different from the sign of the original number, e.g.
   '-0.001' printShowingDecimalPlaces: 2

Then I simplified the method considerably, and again all its tests pass. This newer version is fcsPrintShowingDecimals.3.cs.gz.

04-11-07 16:27   
I was having problems with:

(953/100) printShowingDecimalPlaces: 2

in Squeak 3.9 7067. The 3.9 version prodces 9.52 but the correct result should be 9.53. The fcsNumberPrintShowingDecimals.3.cs.gz change set fixed this problem and hasn't caused me any problems in my development image.
nicolas cellier   
11-24-07 00:43   
I totally agree with second patch, though i would maybe write:

^sign , (integerString
        copyReplaceFrom: integerString size - placesDesired + 1
        to: integerString size - placesDesired
        with: '.').
11-24-07 10:25   
This now is 7157fcsPrintShowingDecimals.cs and was in 3.10 updates.
Thanks Frank !
nicolas cellier   
03-24-08 14:35   
Unfortunately i can exhibit some failure tests.
First try this little overflow:

(1.0d306 printShowingDecimalPlaces: 3).

I can also build another case with an inexact rounding:
5000000000000001.0 printShowingDecimalPlaces: 0. "-> 5000000000000002"

Above number is on 53 bits and thus represented exactly asFloat, it should therefore print exactly, but rounded algorithm is inexact....
Funnily, this number works with any other decimal places than 0.

I can exploit the Float rounded inexact operation to construct a test case that fails with more decimal places:

50000000000001.25 printShowingDecimalPlaces: 2. "-> 50000000000001.26"

50000000000001.25 is also represented exactly (200000000000005.0 timesTwoPower: -2, with 200000000000005 highBit -> 48).

The only way to do it exactly is to convert early to costly arithmetic:
self asTrueFraction roundTo: (10 raisedTo: placesDesired) reciprocal.

nicolas cellier   
03-24-08 16:12   
"fix begin"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Patch-M5640-nice.1.cs '
"fix test"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Test-M5640-nice.1.cs'.
"fix end"
nicolas cellier   
04-23-08 22:46   
Arg, i blindly approved and copied the stupid padded right bug reported at 0007028
Here we go again...
test.2.cs also includes a test for 0007028

"fix begin"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Patch-M5640-nice.2.cs '
"fix test"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Test-M5640-nice.2.cs'.
"fix end"

05-09-08 18:35   
"fix begin"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Patch-M5640-nice.2.cs'.
"fix test"
Installer mantis bug: 5640 fix:'Number-printShowingDecimalPlace-Test-M5640-nice.2.cs'.
"fix end"
nicolas cellier   
09-16-08 21:22   
I suggest this issue be closed (if harvested in 7157 as announced).
Any follow-up discussion should then take place at 0007028
01-07-09 16:48   
I would like to close this issue and move discussion to another, perhaps 0007028. But I would like to make sure we are all clear on the current status. Update 7157 [^]

harvests fcsPrintShowingDecimals.cs.gz of Dec 15th, 2006, not fcsNumberPrintShowingDecimals.3.cs.gz of Feb 14th, 2007.

nicolas cellier   
09-19-09 20:22   
Fixed in