On Wed, Jan 3, 2024 at 4:09 PM Aaron Meurer <asmeu...@gmail.com> wrote:
> sign(z) = z/|z| is a fairly standard definition. See > https://oeis.org/wiki/Sign_function and > https://en.wikipedia.org/wiki/Sign_function. It's also implemented > this way in MATLAB and Mathematica (see > https://www.mathworks.com/help/symbolic/sign.html and > https://reference.wolfram.com/language/ref/Sign.html). The function > z/|z| is useful because it represents a normalization of z as a vector > in the complex plane onto the unit circle. > > With that being said, I'm not so sure about the suggestion about > extending copysign(x1, x2) as |x1|*sign(x2). I generally think of > copysign as a function to manipulate the floating-point representation > of a number. It literally copies the sign *bit* from x2 into x1. It's > useful because of things like -0.0, which is otherwise difficult to > work with since it compares equal to 0.0. I would find it surprising > for copysign to do a numeric calculation on complex numbers. Also, > your suggested definition would be wrong for 0.0 and -0.0, since > sign(0) is 0, and this is precisely where copysign matters. > Agreed on all points. -- Robert Kern
_______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com