Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

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

Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Status: Accepted
Owner: [hidden email]
CC: [hidden email]
Labels: Difficulty-Easy Type-Enh Importance-High

New issue 5590 by [hidden email]: Rounding a float: 10.123 round: 2  
=> 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

Here is the test that comes with:
testRounding
        "
        self debug: #testRounding
        "

        self assert: (10.1234 round: 2) = 10.12.
        self assert: (10.1234 round: 0) = 10


I have been missing this features for years (literally!)


Attachments:
        RoundingFloat.2.cs  1.8 KB


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: FixReviewNeeded
        Labels: Milestone-2.0

Comment #1 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo

Comment #2 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

all the other rounding methods can be called on all Numbers.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo

Comment #3 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

looks fine for me. What do you mean? we need a super #round: method?



_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo

Comment #4 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

yes, so that 1 round: 2 is 1.




_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Cc: [hidden email]

Comment #5 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

Nicolas could you have a look at this fix? Thanks


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo

Comment #6 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

asInteger will truncate not round, try
   0.126 round: 2.
So #asInteger must be replaced with #rounded.

As for selector name, the intention is roundToDecimalPlaces: but you may  
prefer round:...

The operations are inexact but maybe it's enough for your needs, I don't  
know...
It's yet better than rounTo: 0.01, because (10 raisedTo: n) is exact up to  
n = 22 (5^3 < 2^7, 5^21 < 2^49, 5^22 < 2^52)
(20 to: 30) detect: [:n | (10 raisedTo: n) asFloat asInteger ~= (10  
raisedTo: n)].
-> 23

Despite this good property, here is an illustration of inexactness of the  
multiplication (self * (10 raisedTo: n)) :
0.995 < (995/1000) -> true, so (0.995 printShowingDecimalPlaces: 2)  
-> '0.99'.
Though, (0.995 * 100) rounded -> 100, so (0.995 round: 2) -> 1.0 (once you  
use rounded rather than asInteger).
If such mismatch does not matter, then proceed with the modified version  
(rounded instead of asInteger).
Otherwise, the same algorithm than printString must be used.
The one in http://ss3.gemstone.com/ss/NumberPrinter.html is better than  
current usage of asTrueFraction in printShowingDecimalPlaces, because it  
avoid printing of insignificand digits.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: FixToInclude

Comment #7 on issue 5590 by [hidden email]: Rounding a float:  
10.123 round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

in:  
SLICE-Issue-5590-Rounding-a-float-10123-round-2-gt-1012-GuillermoPolito.1

We decided when rounding fractions to convert it to float before.

With camille we provide an implementation based on the changeset making all  
numbers polymorphic and tests for fractions, floats and integers


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: FixReviewNeeded

Comment #8 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo

Comment #9 on issue 5590 by [hidden email]: Rounding a float: 10.123  
round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

This is cool!


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: FixToInclude

Comment #10 on issue 5590 by [hidden email]: Rounding a float:  
10.123 round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

(No comment was entered for this change.)


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: Integrated

Comment #11 on issue 5590 by [hidden email]: Rounding a float:  
10.123 round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

in 2.0 159


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: Workneeded

Comment #12 on issue 5590 by [hidden email]: Rounding a float:  
10.123 round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

marcus are you sure that this rounding is good. I could not make a choice  
based on nicolas feedback may be I was not precise enough.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker
Reply | Threaded
Open this post in threaded view
|

Re: Issue 5590 in pharo: Rounding a float: 10.123 round: 2 => 10.12

pharo
Updates:
        Status: Integrated

Comment #13 on issue 5590 by [hidden email]: Rounding a float:  
10.123 round: 2 => 10.12
http://code.google.com/p/pharo/issues/detail?id=5590

Yes, the second iteration uses #rounded and implements it for integer.


_______________________________________________
Pharo-bugtracker mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-bugtracker