[BUGLET] in Float>raisedTo:

sqrmax at cvtci.com.ar sqrmax at cvtci.com.ar
Fri Feb 19 20:53:41 UTC 1999


Hi.

>There is another buglet in the raisedTo: setup:
>  -1.1 raisedTo: 3 -> 0.0 (and a log DOMAIN error on stderr).

Ouch yes... floats will be sent ln...

>  -1 raisedTo: 3   -> -1

But this is correct.

>The problem is that Number>>raisedTo: checks the class of its argument,
>and if it is an integer uses Number>>raisedToInteger:, but
>Float>>raisedTo: does not check the argument, and produces the incorrect
>result (and the DOMAIN error).

>The obvious fix is:
>
>  raisedTo: aNumber
>	"Answer the receiver raised to aNumber."
>	(aNumber isInteger)
>		ifTrue: ["Do the special case of integer power"
>				^self raisedToInteger: aNumber].
>
>	0.0 = aNumber ifTrue: [^ 1.0].  "special case for 0.0 raisedTo: 0.0"
>	^ (self ln * aNumber asFloat) exp

Note that this still won't fix sending ln to a negative number. It could be 
done like this as well:

>	^(self abs ln * aNumber asFloat) exp * self sign

Andres.





More information about the Squeak-dev mailing list