[squeak-dev] Re: Complex isNumber

nicolas cellier ncellier at ifrance.com
Tue Mar 11 23:45:34 UTC 2008


Andreas Raab a écrit :
> If the goal is to fix Number vs. Complex comparison, isn't the correct 
> behavior to renormalize Complex numbers when they are indeed reals? 
> I.e., my attitude would be to fix Complex such that (1 + 0i) results in 
> a real number (the integer 1) instead of the complex (1 + 0i). In which 
> case the comparison problem solves itself.


I share this view. That's how VW did, like 4/2 won't answer a Fraction.
The only advantages of making Complex static are i guess to have things like

	(-4 + 0 i) sqrt

behave differently than

	-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.


  Lacking this, I would rather
> have comparison fail for real vs. complex and require clients to be 
> explicit where they mix them, e.g., force you to write "x asComplex = y".
> 

Yes very much like Point:
0 = (0 @ 0). "false"
(0 @ 0) = 0. "false"
(0 @ 0) = 0 asPoint. "true"


> In any case, pretending to be a number when indeed Complex is lacking 
> half of the protocol of numbers is not the right way to address the 
> problem.
> 
> Cheers,
>   - Andreas
> 

Indeed, you formulated it better.
It's like we are trying to mix above two approaches with dangerous hacks.

Nicolas




More information about the Squeak-dev mailing list