-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Add support for sympy.sign in .printing.pycode #14010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
|
Nice catch! (I'm surprised that copysign isn't returning NAN here). But isn't that a "bug" in |
|
It's probably because it just copies the sign bit and NaN has a sign bit. |
|
I tracked down the issue. The problem does not lie in One possible work-around would be to define the method |
|
@ylemkimon since the |
ylemkimon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant a discrepancy between SymPy's sign returning NaN for NaN and Python's copysign returning +-1 for NaN, but it's an implementation issue, not a code printer should handle. LGTM 😄
This is half issue, half PR - I'm not 100% sure exactly how this should be correctly implemented, and I'm not necessarily going to have time to test this further, but the fix is small enough and the code change demonstrates the issue better than an issue would. As I understand it, `sympy.sign` is defined to return 0 for 0. Other code printers also implement it this way, see for example sympy#14010. Rust's `signum` returns 1 or -1 for 0 (depending on the sign of the 0, for floats with signed zeroes), which isn't correct.
This is half issue, half PR - I'm not 100% sure exactly how this should be correctly implemented, and I'm not necessarily going to have time to test this further, but the fix is small enough and the code change demonstrates the issue better than an issue would. As I understand it, `sympy.sign` is defined to return 0 for 0. Other code printers also implement it this way, see for example sympy#14010. Rust's `signum` returns 1 or -1 for 0 (depending on the sign of the 0, for floats with signed zeroes), which isn't correct.
This is half issue, half PR - I'm not 100% sure exactly how this should be correctly implemented, and I'm not necessarily going to have time to test this further, but the fix is small enough and the code change demonstrates the issue better than an issue would. As I understand it, `sympy.sign` is defined to return 0 for 0. Other code printers also implement it this way, see for example sympy#14010. Rust's `signum` returns 1 or -1 for 0 (depending on the sign of the 0, for floats with signed zeroes), which isn't correct.
This is half issue, half PR - I'm not 100% sure exactly how this should be correctly implemented, and I'm not necessarily going to have time to test this further, but the fix is small enough and the code change demonstrates the issue better than an issue would. As I understand it, `sympy.sign` is defined to return 0 for 0. Other code printers also implement it this way, see for example sympy#14010. Rust's `signum` returns 1 or -1 for 0 (depending on the sign of the 0, for floats with signed zeroes), which isn't correct.
This is half issue, half PR - I'm not 100% sure exactly how this should be correctly implemented, and I'm not necessarily going to have time to test this further, but the fix is small enough and the code change demonstrates the issue better than an issue would. As I understand it, `sympy.sign` is defined to return 0 for 0. Other code printers also implement it this way, see for example sympy#14010. Rust's `signum` returns 1 or -1 for 0 (depending on the sign of the 0, for floats with signed zeroes), which isn't correct.
Python doesn't have a
math.signfunction, it does have acopysignfunction though, however, just wrapping copysign would not give the right answer forsign(0)(hence the use of the ternary operator).