[BUGLET] in Float>raisedTo:

Juan Cires Martinez jcm at mat.upm.es
Fri Feb 19 18:24:22 UTC 1999

There is another buglet in the raisedTo: setup:

  -1.1 raisedTo: 3 -> 0.0 (and a log DOMAIN error on stderr).
  -1 raisedTo: 3   -> -1

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

Saludos, Juan.

More information about the Squeak-dev mailing list