[squeak-dev] The Trunk: Kernel-nice.1043.mcz
commits at source.squeak.org
commits at source.squeak.org
Sat Oct 1 20:19:45 UTC 2016
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.1043.mcz
==================== Summary ====================
Name: Kernel-nice.1043
Author: nice
Time: 1 October 2016, 10:19:12.37443 pm
UUID: d29f9c07-edc8-4add-9b99-e889fd2be32a
Ancestors: Kernel-nice.1042
Fix (10 raisedTo: 600) nthRoot: 300.
It did incorrectly return 126.0 instead of 100.
=============== Diff against Kernel-nice.1042 ===============
Item was changed:
----- Method: Integer>>nthRootTruncated: (in category 'mathematical functions') -----
nthRootTruncated: aPositiveInteger
"Answer the integer part of the nth root of the receiver."
+ | guess guessToTheNthMinusOne nextGuess |
- | guess guessToTheNthMinusOne delta |
self = 0 ifTrue: [^0].
self negative
ifTrue:
[aPositiveInteger even ifTrue: [ ArithmeticError signal: 'Negative numbers don''t have even roots.' ].
^(self negated nthRootTruncated: aPositiveInteger) negated].
guess := 1 bitShift: self highBitOfMagnitude + aPositiveInteger - 1 // aPositiveInteger.
[
guessToTheNthMinusOne := guess raisedTo: aPositiveInteger - 1.
+ nextGuess := (aPositiveInteger - 1 * guess * guessToTheNthMinusOne + self) // (guessToTheNthMinusOne * aPositiveInteger).
+ nextGuess = guess ] whileFalse:
+ [ guess := nextGuess ].
+ ( guess raisedTo: aPositiveInteger) > self ifTrue:
- delta := (guess * guessToTheNthMinusOne - self) // (guessToTheNthMinusOne * aPositiveInteger).
- delta = 0 ] whileFalse:
- [ guess := guess - delta ].
- ( (guess := guess - 1) raisedTo: aPositiveInteger) > self ifTrue:
[ guess := guess - 1 ].
^guess!
More information about the Squeak-dev
mailing list
|