float printing

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

float printing

stephane ducasse
hi guys

here is a point where squeak and pharo could sync. Now I propose the change to be applied in Pharo.

http://code.google.com/p/pharo/issues/detail?id=2888

in essence
        0.1+0.2=0.3
which is normal
        since
        (0.1+0.2) hex '3FD3333333333334'
        0.3 hex '3FD3333333333333'
showing that we are in presence of two difference numbers.
               
So since floats are approximations anyway, I like the idea that the language tells me all the time.
This fits perfectly with the discussion and actions we got last year on floats.
Of course 0.1s2 + 0.2s2 = 0.3s2 is true

storeString is already conveying the right information both in squeak and pharo
       
(0.1+0.2) storeString
        '0.30000000000000004'
0.3 storeString
        '0.3'

I suggest that printString on float ie on little change in printString.
So talk now.
My point is that since we cannot perfectly lie better say it. I think that GNU and python are right so
this an easy fix with a really good impact on education.

Stef



printOn: aStream base: base
        "Handle sign, zero, and NaNs; all other values passed to absPrintOn:base:"

        self isNaN ifTrue: [aStream nextPutAll: 'NaN'. ^ self]. "check for NaN before sign"
        self > 0.0
                ifTrue: [self absPrintExactlyOn: aStream base: base]
                ifFalse:
                        [self sign = -1
                                ifTrue: [aStream nextPutAll: '-'].
                        self = 0.0
                                ifTrue: [aStream nextPutAll: '0.0'. ^ self]
                                ifFalse: [self negated absPrintOn: aStream base: base]]
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project