FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-133895: provide C99 Annex G return values for cmath's functions by skirpichev · Pull Request #134995 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (1) .rst  (3) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions Doc/library/cmath.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ the function is then applied to the result of the conversion.
1.4142135623730951j


Most functions compute and return the C99 Annex G recommended result.
If the standard recommends raising ``FE_DIVBYZERO`` or ``FE_INVALID``
floating-point exceptions, a :exc:`ValueError` is raised and the recommended
result is available as the ``value`` attribute of the exception object.
If a range error occurs due to an overflow in any component of the result,
an :exc:`OverflowError` is raised.


==================================================== ============================================
**Conversions to and from polar coordinates**
--------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.15.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ calendar
dark mode and have been migrated to the HTML5 standard for improved accessibility.
(Contributed by Jiahao Li and Hugo van Kemenade in :gh:`137634`.)

cmath
-----

* Provide C99 Annex G return values for :mod:`cmath`'s functions as the
``value`` attribute of exception objects.
(Contributed by Sergey B Kirpichev in :gh:`133895`.)

collections
-----------
Expand Down
13 changes: 7 additions & 6 deletions Lib/test/test_cmath.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,23 @@ def polar_complex(z):
if 'divide-by-zero' in flags or 'invalid' in flags:
try:
actual = function(arg)
except ValueError:
continue
except ValueError as exc:
actual = exc.value
else:
self.fail('ValueError not raised in test '
'{}: {}(complex({!r}, {!r}))'.format(id, fn, ar, ai))

if 'overflow' in flags:
elif 'overflow' in flags:
try:
actual = function(arg)
except OverflowError:
continue
except OverflowError as exc:
actual = exc.value if fn != 'polar' else complex(*exc.value)
else:
self.fail('OverflowError not raised in test '
'{}: {}(complex({!r}, {!r}))'.format(id, fn, ar, ai))

actual = function(arg)
else:
actual = function(arg)

if 'ignore-real-sign' in flags:
actual = complex(abs(actual.real), actual.imag)
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Provide C99 Annex G return values for :mod:`cmath`'s functions as the
``value`` attribute of exception objects. Patch by Sergey B Kirpichev.
Loading
Loading

Back | FazBrowse Home | New Git URL