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

gh-156695: Improve accuracy of complex div and pow by hpkfft · Pull Request #156968 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .c  (1) .h  (2) .rst  (1) All 3 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
23 changes: 23 additions & 0 deletions Include/internal/pycore_complexobject.h
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 @@ -27,6 +27,29 @@ PyAPI_FUNC(Py_complex) _Py_cr_prod(Py_complex, double);
PyAPI_FUNC(Py_complex) _Py_cr_quot(Py_complex, double);
PyAPI_FUNC(Py_complex) _Py_rc_quot(double, Py_complex);

static inline bool
_Py_c_isnan(Py_complex a)
{
return isnan(a.real) || isnan(a.imag);
}

static inline bool
_Py_c_isinf(Py_complex a)
{
return isinf(a.real) || isinf(a.imag);
}

static inline bool
_Py_c_isfinite(Py_complex a)
{
return isfinite(a.real) && isfinite(a.imag);
}

static inline bool
_Py_c_iszero(Py_complex a)
{
return a.real == 0.0 && a.imag == 0.0;
}
Comment on lines +30 to +52

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That, probably, can go to a separate pr. I can do this, if core devs are interested.

This pr touches many things and it's good to make it in some more manageable pieces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, I would like it if you put this in a separate PR. Then I'll merge with main, and my diff will be smaller!
Also, it's your idea and your work. (I thought it had been merged already, and I was using it locally, so I didn't want to make the effort to revert it locally before pushing this PR.)

Honestly, I've lost track of all the issues and PRs that affect complexobject.c....


#ifdef __cplusplus
}
Expand Down
21 changes: 3 additions & 18 deletions Include/internal/pycore_pymath.h
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 @@ -10,10 +10,9 @@ extern "C" {


/* _Py_ADJUST_ERANGE1(x)
* _Py_ADJUST_ERANGE2(x, y)
* Set errno to 0 before calling a libm function, and invoke one of these
* macros after, passing the function result(s) (_Py_ADJUST_ERANGE2 is useful
* for functions returning complex results). This makes two kinds of
* Set errno to 0 before calling a libm function, and invoke this
* macro after, passing the function result(s).
* This makes two kinds of
* adjustments to errno: (A) If it looks like the platform libm set
* errno=ERANGE due to underflow, clear errno. (B) If it looks like the
* platform libm overflowed but didn't set errno, force errno to ERANGE. In
Expand Down Expand Up @@ -42,20 +41,6 @@ static inline void _Py_ADJUST_ERANGE1(double x)
}
}

static inline void _Py_ADJUST_ERANGE2(double x, double y)
{
if (x == INFINITY || x == -INFINITY ||
y == INFINITY || y == -INFINITY)
{
if (errno == 0) {
errno = ERANGE;
}
}
else if (errno == ERANGE) {
errno = 0;
}
}


//--- HAVE_PY_SET_53BIT_PRECISION macro ------------------------------------
//
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,3 @@
Improve accuracy of complex division and complex powers with small negative
integer exponents. This also applies to :c:func:`_Py_c_quot` and
:c:func:`_Py_c_pow`. Contributed by High Performance Kernels LLC.
Loading
Loading

Back | FazBrowse Home | New Git URL