On Wed Nov 19 07:35:48 2008, masak wrote:
masak what should the behaviour of sign($x) be when $x is complex?
I'd argue that it's a Failure.
If you care about complex numbers, you usually want an angle instead,
which you can get with Complex.polar. (And it's easier to give it a
another meaning later that way)
(If you wanted a complex number with magnitude one, then you should call
that method phase or so, but that would confuse most people when
talking about real numbers.)
Cheers,
Moritz
masak rakudo: say sign($_) for 42, -42, 0+42i
p6eval rakudo 32877: OUTPUT[1-11]
masak somehow, that last one doesn't feel right to me.
masak I vote for either an error or $x/abs($x)
PerlJam why would it be an error?
masak because 'sign' could be argued to only be applicable to real
numbers.
masak i.e. positive numbers, negative numbers, and zero.
PerlJam but what is it specced to do? :-)
masak ah.
masak it's supposed to return the 'sign' of a number.
masak i.e. +1, -1 or 0 for the above three groups.
masak in that way, it's a bit like =, except it always compares to
0
PerlJam oh, it's wrong anyway I think.
PerlJam rakudo: say sign(-5+3i);
p6eval rakudo 32877: OUTPUT[1]
PerlJam that can't be right.
masak it always returns 1 on complex numbers.
* masak reports a bug