[Pkg] The Trunk: Kernel-nice.647.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Nov 2 18:50:56 UTC 2011
Nicolas Cellier uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-nice.647.mcz
==================== Summary ====================
Name: Kernel-nice.647
Author: nice
Time: 2 November 2011, 7:50:14.247 pm
UUID: 68374059-00c3-4605-bfb3-615f3793071a
Ancestors: Kernel-nice.646
Optimize #ln and #log as in Pharo.
1) SmallInteger just inherits from super (^self asFloat log)
2) LargePositiveInteger can avoid self > à guard
3) LargeNegativeInteger can goto Error (no raise, just kidding)
4) Fraction can avoid arithmetic because (a/b) log = (a log - b log) and because a log or b log are unlikely to overflow - (10 raisedTo: (10 raisedTo: 308)) is likely to exhaust your memory before any overflow occurs ;).
=============== Diff against Kernel-nice.646 ===============
Item was changed:
----- Method: Fraction>>ln (in category 'mathematical functions') -----
ln
+ "This function is defined because super ln might overflow."
+ | res |
- "This function is defined because super ln might overflow.
- Note that < 1 is tested before converting to float in order to avoid precision loss due to gradual underflow."
- | res int |
self <= 0 ifTrue: [DomainError signal: 'ln is only defined for x > 0'].
+ "Test self < 1 before converting to float in order to avoid precision loss due to gradual underflow."
+ numerator < denominator ifTrue: [^self reciprocal ln negated].
- self < 1 ifTrue: [^self reciprocal ln negated].
res := super ln.
res isFinite ifTrue: [^res].
+ ^numerator ln - denominator ln!
- int := self integerPart.
- ^int ln + (self / int) ln!
Item was changed:
----- Method: Fraction>>log (in category 'mathematical functions') -----
log
+ "This function is defined because super log might overflow."
+ | res |
- "This function is defined because super log might overflow.
- Note that < 1 is tested before converting to float in order to avoid precision loss due to gradual underflow."
- | res int |
self <= 0 ifTrue: [DomainError signal: 'log is only defined for x > 0'].
+ "Test self < 1 before converting to float in order to avoid precision loss due to gradual underflow."
+ numerator < denominator ifTrue: [^self reciprocal log negated].
- self < 1 ifTrue: [^self reciprocal log negated].
res := super log.
res isFinite ifTrue: [^res].
+ ^numerator log - denominator log!
- int := self integerPart.
- ^int log + (self / int) log!
Item was removed:
- ----- Method: Integer>>ln (in category 'mathematical functions') -----
- ln
- "This function is defined because super ln might overflow."
- | res h |
- self <= 0 ifTrue: [DomainError signal: 'ln is only defined for x > 0'].
- res := super ln.
- res isFinite ifTrue: [^res].
- h := self highBit.
- ^2 ln * h + (self / (1 << h)) asFloat ln!
Item was removed:
- ----- Method: Integer>>log (in category 'mathematical functions') -----
- log
- "This function is defined because super log might overflow."
- | res h |
- self <= 0 ifTrue: [DomainError signal: 'log is only defined for x > 0'].
- res := super log.
- res isFinite ifTrue: [^res].
- h := self highBit.
- ^2 log * h + (self / (1 << h)) asFloat log!
Item was added:
+ ----- Method: LargeNegativeInteger>>ln (in category 'mathematical functions') -----
+ ln
+ ^DomainError signal: 'ln is only defined for x > 0' from: 0!
Item was added:
+ ----- Method: LargeNegativeInteger>>log (in category 'mathematical functions') -----
+ log
+ ^DomainError signal: 'log is only defined for x > 0' from: 0!
Item was added:
+ ----- Method: LargePositiveInteger>>ln (in category 'mathematical functions') -----
+ ln
+ "This function is defined because super ln might overflow."
+ | res h |
+ res := super ln.
+ res isFinite ifTrue: [^res].
+ h := self highBit.
+ ^2 ln * h + (self / (1 << h)) asFloat ln!
Item was added:
+ ----- Method: LargePositiveInteger>>log (in category 'mathematical functions') -----
+ log
+ "This function is defined because super log might overflow."
+ | res h |
+ res := super log.
+ res isFinite ifTrue: [^res].
+ h := self highBit.
+ ^2 log * h + (self / (1 << h)) asFloat log!
More information about the Packages
mailing list