[squeakdev] Re: Complex isNumber
Andres Valloud
AVALLOUD at roadrunner.com
Wed Mar 12 08:21:50 UTC 2008
Note that there are some contexts in which getting an error when doing
1 sqrt is perfectly valid. For example, if the idea is to implement
pythagoras' theorem, then taking the square root of a negative number is
an indication of deep trouble somewhere.
The issue is that there are some other contexts in which getting 0 + 1i
is reasonable, and that because the determination of what should happen
cannot be made at compile time, whatever decision is made is wrong by
definition.
There has to be a way in which a number knows it belongs to the "real"
(or their rational approximations usually used in computers) or to the
complex numbers. If numbers knew this, then there could be two
different implementations of sqrt, and since the choice of which number
to use would be done at compile time (as instructed by a developer
clearly revealing his/her intention) there would be no confusion
regarding what is the correct course of action for the given situation.
It's funny... I was just thinking of this in a different context a
moment ago... unfortunately I haven't figured out a way to do this I am
happy with yet.
Andres.
Paolo Bonzini wrote:
>
>> So from my perspective it would be completely fair to take the only
>> sensible interpretation of 1 sqrt and create a Complex by default.
>
> I fully agree.
>
> Regarding sorting, in GNU Smalltalk I did something, ahem, bold and
> decided that comparison methods would compare the absolute values.
> Wellbehaved applications won't call comparison methods on complex
> numbers anyway.
>
> Paolo
>
>
More information about the Squeakdev
mailing list
