On Thu, Nov 20, 2008 at 8:34 AM, Carl Mäsak <[EMAIL PROTECTED]> wrote: > I guess the question is more about the programmer's expectations. Is > this a case where we serve the programmer better by returning Failure, > or by generalizing the C<sign> function to the complex plane?
This is parallel to the case for sqrt($x) for $x<0. Which does not by default return Failure, but neither does it return a complex result - it returns NaN. Is that the spec'ed behavior? On the one hand, as long as sqrt() *doesn't* uncomplainingly return complex numbers for negative inputs, it would seem that one is rather less likely to have a complex number when expecting a real than to have a negative when expecting a positive. So having sgn() return complex results for complex inputs is somewhat safer than having sqrt() return complex results for negative inputs. On the other hand, a lot of code will be expecting the return value of sign() to always be one(-1,0,1), and might break horribly if that's not the case. 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. -- Mark J. Reed <[EMAIL PROTECTED]>