'From Squeak3.10beta of 22 July 2007 [latest update: #7137] on 1 December 2007 at 6:59:56 pm'!
"Change Set: FloatRaisedTo-M6781-nice-patch
Date: 1 December 2007
Author: nice
(0.0 raisedTo: -1). correctly raise a ZeroDivide
(0.0 raisedTo: -1.0) ... well, answer 0.0, hem...
This is a patch
I republish to invert exponent=1 and self=0 test and to correct a wrong assertion I put in a comment"!
!Float methodsFor: 'mathematical functions' stamp: 'nice 12/1/2007 18:58'!
raisedTo: aNumber
"Answer the receiver raised to aNumber."
aNumber isInteger ifTrue:
["Do the special case of integer power"
^ self raisedToInteger: aNumber].
self < 0.0 ifTrue:
[ ArithmeticError signal: ' raised to a non-integer power' ].
0.0 = aNumber ifTrue: [^ 1.0]. "special case for exponent = 0.0"
1.0 = aNumber ifTrue: [^ self]. "special case for exponent = 1.0"
self= 0.0 ifTrue: [ "special case for self = 0.0"
aNumber < 0.0
ifTrue: [^ (ZeroDivide dividend: self) signal]
ifFalse: [^ 0.0]].
^ (self ln * aNumber asFloat) exp "otherwise use logarithms"
"NOTES:
(0.0 raisedTo: 0.0) will answer 1.0, as do other languages and libraries like C libm pow(0.0,0.0)
This is questionable, it could as well raise an Exception or answer NaN.
(Float negativeZero raisedTo: anything positive else than 1.0 will answer zero, which is also questionable.
It could follow rule of something negative raisedTo: a non integer power.
(Float nan raisedTo: 0.0) will answer 1.0 as does C libm.so.6 pow(0.0/0.0,0.0)
This is ... surprising.
(0.0 raisedTo: Float nan) will answer 0.0 while C libm.so.6 would answer NaN
This is ... surprising."! !