On Thu, Nov 20, 2008 at 4:25 PM, Wolfgang Laun <[EMAIL PROTECTED]> wrote: > So, calling sqrt with a real < 0, should not come back with a complex > number.
Again, I think this should depend on context. In Perl5, simply use'ing "Math::Complex" changes the behavior of sqrt such that sqrt(-1) returns i. That fits with the fact that 1/2 returns 0.5, and not zero (unlike certain other languages); I don't have to coerce one of the operands to a float to get a float result. I want to keep that sort of DWIMmishness - if I'm computing with complex numbers, reals should be autopromoted without my having to convert them manually. So simply making sqrt a multi doesn't quite suffice. > Calling sqrt with a complex z where Re(z) < 0 and Im(z)=0 should return a > complex number. Agreed. (Side topic: what about autodemotion? Should calling sqrt with a complex z where Re(z) >= 0 and Im(z) = 0 return a complex or a real?) > Calling sgn() with a complex - why not give me what I'm (obviously) asking > for? My only objection to that behavior was that I want to avoid surprise interactions; a lot of code assumes that sgn() can only return one of three values. As long as it's sufficiently unlikely that a Complex will show up when the programmer isn't expecting it, I'm fine with just having sgn() return 0 for 0 and z/abs(z) for everything else. -- Mark J. Reed <[EMAIL PROTECTED]>