z declared complex, sign(z^2) gives pz. Shouldn't it be pnz?j declared imaginary, sign(j^2) gives pz. Shouldn't it be nz?(csign answers correctly.)
The documentation for sign says:
Note that this function assumes that
expris a real-valued expression
But should it also assume this when the user explicitly declared something as complex or imaginary?
Since
signis clearly documented as assuming that its argument is a real-valued expression, I would argue that as soon as it sees anything explicitly complex, it should raise an error, even if the overall value of the expression is real.That is, all the following cases should raise an error:
The error should be something like
:The
signfunction is only defined for expressions not involving complex quantities.The rationale is that if it acts as though it works on any complex quantities, users will have the reasonable expectation that it will work in general with complex quantities, such as
sqrt(x), log(x), asin(x), ....After all,
sign(sqrt(x))doesn't even ask whether whetherxis negative.