--- a/LimitedPrecisionReal.st Sat Mar 06 11:06:53 2010 +0100
+++ b/LimitedPrecisionReal.st Sat Mar 06 12:27:34 2010 +0100
@@ -524,13 +524,25 @@
Implementation takes care of preserving class and avoiding overflow/underflow
Thanks to Nicolas Cellier for this code"
- |half two|
+ |half two h1 h2|
two := self coerce:2.
anInteger abs highBit >= (self class numBitsInExponent - 2) ifTrue:[
half := anInteger // 2.
- ^ (self * (two raisedToInteger: half)) * (two raisedToInteger: anInteger - half)
+
+ anInteger even ifTrue:[
+ "/ halves are equal
+ h2 := h1 := (two raisedToInteger: half).
+ ] ifFalse:[
+ h1 := (two raisedToInteger: half).
+ anInteger > 0 ifTrue:[
+ h2 := h1 * two.
+ ] ifFalse:[
+ h2 := (two raisedToInteger: anInteger - half).
+ ].
+ ].
+ ^ (self * h1) * h2
] ifFalse: [
^ self * (two raisedToInteger: anInteger).
]
@@ -539,7 +551,20 @@
(1 asShortFloat timesTwoPower: 3) class = ShortFloat.
(1 asLongFloat timesTwoPower: 1024).
(1 asFloat timesTwoPower: -1024) timesTwoPower: 1024.
- (2.0 timesTwoPower: -150) timesTwoPower: 150
+
+ (2.0 asShortFloat timesTwoPower: -150) timesTwoPower: 150
+ (2.0 asLongFloat timesTwoPower: -150) timesTwoPower: 150
+ (2.0 asFloat timesTwoPower: -150) timesTwoPower: 150
+
+ (2.0 asShortFloat timesTwoPower: -149) timesTwoPower: 149
+ (2.0 asLongFloat timesTwoPower: -149) timesTwoPower: 149
+ (2.0 asFloat timesTwoPower: -149) timesTwoPower: 149
+
+ Time millisecondsToRun:[
+ 1000000 timesRepeat:[
+ (2.0 timesTwoPower: 150)
+ ]
+ ]
"
! !
@@ -1173,11 +1198,11 @@
!LimitedPrecisionReal class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.71 2010-03-06 10:04:54 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.72 2010-03-06 11:27:34 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.71 2010-03-06 10:04:54 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.72 2010-03-06 11:27:34 cg Exp $'
! !
LimitedPrecisionReal initialize!