[squeak-dev] Re: Complex isNumber

Andreas Raab andreas.raab at gmx.de
Wed Mar 12 04:08:37 UTC 2008

nicolas cellier wrote:
>     -4 sqrt
> (or try ln, because base image Complex does not even understand sqrt).
> Two alternatives are having a special complexSqrt (does not sound good), 
> or modify Number>>sqrt.
> VW propose to raise Exceptions and provide handlers, but i don't feel it 
> satisfying. I want some library of code to be Complex-free and raise an 
> Error, whether or not invoked from a complex-full part.

Good points. Though, I would argue that for practical purposes there is 
probably very little difference between raising an error or going 
complex when you request -1 sqrt.

No code that I have seen has ever taken a "corrective" approach to the 
problem (by handing the negative sqrt condition and fixing the problem 
in the handler) but always been preemptive. Either by checking the input 
or by having separate methods which are implied to check the input (for 
example we use #arcCosClamped which implicitly clamps the input to -1 
... +1 in situations where we may get results out of range due to 
conversion problems).

Code that isn't preemptive in this manner is very likely going to blow 
up either way and I don't think it matters very much if that is because 
of the negative sqrt or some follow-on problem with Complex. In 
particular considering that unless you use the "corrective" approach 
your code is broken to begin with if it allows unintentional negative 
input. Checking the image (there are only 34 senders of sqrt in 3.9) 
certainly indicates that the usage of sqrt is almost always related to 
length calculations in which case this whole discussion is moot.

So from my perspective it would be completely fair to take the only 
sensible interpretation of -1 sqrt and create a Complex by default.

   - Andreas

More information about the Squeak-dev mailing list