[Pkg] The Trunk: Collections-ul.453.mcz
commits at source.squeak.org
commits at source.squeak.org
Thu Aug 4 01:28:21 UTC 2011
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.453.mcz
==================== Summary ====================
Name: Collections-ul.453
Author: ul
Time: 4 August 2011, 3:24:13.104 am
UUID: 7dcede35-8732-c14f-8035-61be4793b776
Ancestors: Collections-ul.452
SequenceableCollection >> #polynomialEval: uses Horner's scheme.
=============== Diff against Collections-ul.452 ===============
Item was changed:
----- Method: SequenceableCollection>>polynomialEval: (in category 'enumerating') -----
polynomialEval: thisX
"Treat myself as the coeficients of a polynomial in X. Evaluate it with thisX. First element is the constant and last is the coeficient for the highest power."
" #(1 2 3) polynomialEval: 2 " "is 3*X^2 + 2*X + 1 with X = 2"
+ | index sum |
+ sum := self at: (index := self size).
+ [ (index := index - 1) >= 1 ] whileTrue: [
+ sum := sum * thisX + (self at: index) ].
+ ^sum!
- | size sum valToPower |
- sum := self at: 1.
- (size := self size) = 1 ifTrue: [ ^sum ].
- valToPower := thisX.
- 2 to: size - 1 do: [ :ind |
- sum := sum + ((self at: ind) * valToPower).
- valToPower := valToPower * thisX ].
- ^sum + ((self at: size) * valToPower)!
More information about the Packages
mailing list