J Pfersich wrote:
> st> -8 roundTo: 3 !
> -6 ===============> incorrect, should be -9
> st> 8 roundTo: 3 !
> 9 ===============> correct
Right. And there's another bug a couple lines above:
st> ((30 factorial + (1/4)) rounded - 30 factorial) printNl!
9581293239009280
Both fixed with the attached patch. Thank you.
Paolo
--- orig/kernel/Number.st
+++ mod/kernel/Number.st
@@ -400,14 +400,14 @@ truncateTo: aNumber
rounded
"Returns the integer nearest the receiver"
^self negative
- ifTrue: [ (self - 0.5) ceiling ]
- ifFalse: [ (self + 0.5) floor ]
+ ifTrue: [ (self - (self unity / 2)) ceiling ]
+ ifFalse: [ (self + (self unity / 2)) floor ]
!
roundTo: aNumber
"Answer the receiver, truncated to the nearest multiple
of aNumber"
- ^(self + (aNumber / 2) / aNumber) integerPart * aNumber
+ ^(self / aNumber) rounded * aNumber
! !
_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk