> Mark (>): >> I think the most sensible thing is to be consistent. sgn() fails for >> non-real input as long as sqrt() returns NaN for negative input. >> Change the latter behavior (via a pragma or whatever) so that sqrt() >> returns complex numbers, and then sgn() should start behaving on such >> numbers. > > I like that. Both sign() and sqrt() will then behave like they usually > do, without complex surprises. But for those who want the generalized > behvaiour, it's only a pragma away. > > // Carl
Rather than a pragma, wouldn't it make more sense to have multi sub sgn(Num) -> Num multi sub sqrt(Num) -> Num behave appropriately for real numbers and multi sub sgn(Complex) -> Complex multi sub sqrt(Complex) -> Complex behave appropriately for complex numbers? So people who want sqrt(-1) be return i must pass in Complex.new(-1,0) or whatever the right syntax is.