| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Now this information is available as the "value" attribute of the ValueError exception object: ```pycon >>> import cmath >>> try: ... cmath.log(complex(-0.0, 0)) ... except ValueError as exc: ... print(exc.value) ... (-inf+3.141592653589793j) ``` Also uses the AC magic for return value of the cmath.rect().
|
CC @abhigyan631 as author of #133923 |
Sorry, something went wrong.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
I changed exception handling along the way, suggested by @serhiy-storchaka. I hope I did that right. If so, I can adjust the math's pr. Now we add value to OverflowError's too. This reveals two bugs (in sinh and cosh), fixed. |
Sorry, something went wrong.
| exc_string = PyUnicode_FromString("math range error"); | ||
| } | ||
| if (!exc_string) { | ||
| Py_DECREF(value); |
There was a problem hiding this comment.
I'm not very fond of stealing a reference here. Maybe we can just return -1 and make the DECREF in the caller?
Sorry, something went wrong.
There was a problem hiding this comment.
Then we just have to put Py_DECREF(value) unconditionally after every set_cmath_error(value) call.
Sorry, something went wrong.
There was a problem hiding this comment.
I think it'll be a bit cleaner (I find following code that doesn't steal references much easier, even if it sometimes leads to more lines). But since you're mainly the one maintaining math/cmath, it's up to you though. I'd appreciate a small comment in the function though to know that 'value' is stolen.
Sorry, something went wrong.
There was a problem hiding this comment.
I think it'll be a bit cleaner
Maybe. Lets other reviewers decide. Meanwhile, I left a comment.
you're mainly the one maintaining math/cmath
No :-)
Sorry, something went wrong.
There was a problem hiding this comment.
Well, you're someone with many contributions in this module!
Sorry, something went wrong.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This is a split-off pythongh-134995. The C17 standard says (cis(y) is defined as cos(y) + i sin(y)): * ccosh(+∞ + i0) returns +∞ + i0. * ccosh(+∞ + iy) returns +∞ cis(y), for finite nonzero y. and * csinh(+∞ + i0) returns +∞ + i0. * csinh(+∞ + iy) returns +∞ cis(y), for positive finite y. So far values, computed for exceptions, aren't accessible from the pure-Python world, yet we are trying to be correct in other places. The Lib/test/mathdata/cmath_testcases.txt has data points with correct numbers (see cosh0032 and sinh0032). Also, use AC magic for the rect() value.
This is a split-off pythongh-134995. The C17 standard says (cis(y) is defined as cos(y) + i sin(y)): * ccosh(+∞ + i0) returns +∞ + i0. * ccosh(+∞ + iy) returns +∞ cis(y), for finite nonzero y. and * csinh(+∞ + i0) returns +∞ + i0. * csinh(+∞ + iy) returns +∞ cis(y), for positive finite y. So far values, computed for exceptions, aren't accessible from the pure-Python world, yet we are trying to be correct in other places. The Lib/test/mathdata/cmath_testcases.txt has data points with correct numbers (see cosh0032 and sinh0032). Also, use AC magic for the rect() value.
|
The scope of this change is larger than just the math module. The decision cannot be made by the reviewers of this PR alone. I'm not sure this is PEP worthy, but at least it's worth discussing with a wider audience. |
Sorry, something went wrong.
@serhiy-storchaka, are you proposing some prior discussion in the "Ideas" section of https://discuss.python.org/? |
Sorry, something went wrong.
|
Yes, please. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Now this information is available as the "value" attribute of raised exception objects, for example:
Also uses the AC magic for return value of the cmath.rect().
📚 Documentation preview 📚: https://cpython-previews--134995.org.readthedocs.build/