[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2022-02-23 Thread STINNER Victor


STINNER Victor  added the comment:

See also bpo-46670: "Build Python with -Wundef: don't use undefined macros".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2022-02-23 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 9bbdde218005f552304d9954bb97e3f9185edded by Victor Stinner in 
branch 'main':
bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)
https://github.com/python/cpython/commit/9bbdde218005f552304d9954bb97e3f9185edded


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2022-02-06 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +29343
pull_request: https://github.com/python/cpython/pull/31171

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:

Include/pymath.h is now better, I close the issue ;-)

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 61190e092b8258ede92ac543bb39bad0f7168104 by Victor Stinner in 
branch 'main':
bpo-45412: Move copysign() define to pycore_pymath.h (GH-28889)
https://github.com/python/cpython/commit/61190e092b8258ede92ac543bb39bad0f7168104


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +27184
pull_request: https://github.com/python/cpython/pull/28889

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 7103356455c8b0c2ba3523929327756413337a31 by Victor Stinner in 
branch 'main':
bpo-45412: Move _Py_SET_53BIT_PRECISION_START to pycore_pymath.h (GH-28882)
https://github.com/python/cpython/commit/7103356455c8b0c2ba3523929327756413337a31


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset a9fe1a8e5b4698937e06c2c419da92e6f78f2ee7 by Victor Stinner in 
branch 'main':
bpo-45412: Update _Py_ADJUST_ERANGE1() comment (GH-28884)
https://github.com/python/cpython/commit/a9fe1a8e5b4698937e06c2c419da92e6f78f2ee7


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:

>  *This isn't reliable.  See Py_OVERFLOWED comments.

Oops, Py_OVERFLOWED() has been removed: I created PR 28884 to fix the comment.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +27178
pull_request: https://github.com/python/cpython/pull/28884

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:

> +1 for the removals. (We should fix #44970 too, but as you say that's a 
> separate issue. And I suspect that the Py_ADJUST_ERANGE1() use for float pow 
> should be replaced, too.)

Well, it's scary of use functions which are documented as:

 * Caution:
 *This isn't reliable.  See Py_OVERFLOWED comments.
 *X and Y may be evaluated more than once.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +27177
pull_request: https://github.com/python/cpython/pull/28882

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 2f92e2a590f0e5d2d3093549f5af9a4a1889eb5a by Victor Stinner in 
branch 'main':
bpo-45412: Remove Py_SET_ERRNO_ON_MATH_ERROR() macro (GH-28820)
https://github.com/python/cpython/commit/2f92e2a590f0e5d2d3093549f5af9a4a1889eb5a


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-11 Thread Mark Dickinson


Mark Dickinson  added the comment:

+1 for the removals. (We should fix #44970 too, but as you say that's a 
separate issue. And I suspect that the Py_ADJUST_ERANGE1() use for float pow 
should be replaced, too.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-09 Thread STINNER Victor


STINNER Victor  added the comment:

> And I have doubts about Py_ADJUST_ERANGE2(). I think that it is used 
> incorrectly. See issue44970.

The question here is if it should be exported in the C API. I propose to remove 
it.

Fixing it is a different issue: bpo-44970 :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

And I have doubts about Py_ADJUST_ERANGE2(). I think that it is used 
incorrectly. See issue44970.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


STINNER Victor  added the comment:

I add Mark Dickinson and Tim Peters who were involved in changes removing usage 
of these macros.

--
nosy: +tim.peters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


STINNER Victor  added the comment:

Py_ADJUST_ERANGE1() is used by float ** float.

Py_ADJUST_ERANGE2() is used by complex ** complex.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


STINNER Victor  added the comment:

Py_SET_ERRNO_ON_MATH_ERROR() documentation also says that it is not reliable:

/* Py_SET_ERRNO_ON_MATH_ERROR(x)
 * If a libm function did not set errno, but it looks like the result
 * overflowed or not-a-number, set errno to ERANGE or EDOM.  Set errno
 * to 0 before calling a libm function, and invoke this macro after,
 * passing the function result.
 * Caution:
 *This isn't reliable.  See Py_OVERFLOWED comments.
 *X is evaluated more than once.
 */

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


STINNER Victor  added the comment:

Py_OVERFLOWED() documentation says that the function is not reliable since C99. 
Python is using C99 since Python 3.6.

/* Py_OVERFLOWED(X)
 * Return 1 iff a libm function overflowed.  Set errno to 0 before calling
 * a libm function, and invoke this macro after, passing the function
 * result.
 * Caution:
 *This isn't reliable.  C99 no longer requires libm to set errno under
 *any exceptional condition, but does require +- HUGE_VAL return
 *values on overflow.  A 754 box *probably* maps HUGE_VAL to a
 *double infinity, and we're cool if that's so, unless the input
 *was an infinity and an infinity is the expected result.  A C89
 *system sets errno to ERANGE, so we check for that too.  We're
 *out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
 *if the returned result is a NaN, or if a C89 box returns HUGE_VAL
 *in non-overflow cases.
 *X is evaluated more than once.
 * Some platforms have better way to spell this, so expect some #ifdef'ery.
 *
 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
 * the longer macro version to be mis-compiled. This isn't optimal, and
 * should be removed once a newer compiler is available on that platform.
 * The system that had the failure was running OpenBSD 3.2 on Intel, with
 * gcc 2.95.3.
 *
 * According to Tim's checkin, the FreeBSD systems use isinf() to work
 * around a FPE bug on that platform.
 */

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


Change by STINNER Victor :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


Change by STINNER Victor :


--
keywords: +patch
pull_requests: +27139
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/28820

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45412] [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), Py_ADJUST_ERANGE1()

2021-10-08 Thread STINNER Victor


New submission from STINNER Victor :

I propose to remove the following macros from the Python C API:

* Py_OVERFLOWED()
* _Py_SET_EDOM_FOR_NAN()
* Py_SET_ERRNO_ON_MATH_ERROR()
* Py_SET_ERANGE_IF_OVERFLOW()
* Py_ADJUST_ERANGE1()
* Py_ADJUST_ERANGE2()

Only Py_ADJUST_ERANGE1() and Py_ADJUST_ERANGE2() are still used by Python 
itself, other macros are no longer used since Python 2.7:

* Py_OVERFLOWED(): no longer used since Python 2.7
* _Py_SET_EDOM_FOR_NAN(): used by Py_SET_ERRNO_ON_MATH_ERROR() which is no 
longer used
* Py_SET_ERRNO_ON_MATH_ERROR(): no longer used since Python 2.6
* Py_SET_ERANGE_IF_OVERFLOW(): no longer used since Python 2.4
* Py_ADJUST_ERANGE1(): used by Objects/floatobject.c
* Py_ADJUST_ERANGE2(): used by Objects/complexobject.c

I searched for these macros in the PyPI top 5000 modules: none of these macros 
are used. There is a single match: frozendict-2.0.6 which contains a 
Include/pyport.h copy, but it doesn't use these macros.

--

Py_OVERFLOWED() was used by long_true_divide() and PyLong_AsDouble() in Python 
2.6, but Python 2.7 no longer used them.


(1) Py_OVERFLOWED() call in long_true_divide() was removed in Python 2.7 by 
bpo-1811:

commit 465728364749e903fb4293b2f7a266b58de6bde4
Author: Mark Dickinson 
Date:   Sun Dec 27 14:55:57 2009 +

Issue #1811:  Improve accuracy and consistency of true division for 
integers.


(2) Py_OVERFLOWED() call in PyLong_AsDouble() was removed in Python 2.7 by 
bpo-3166:

commit 6736cf8d20b67b74e8e959622132963285156242
Author: Mark Dickinson 
Date:   Mon Apr 20 21:13:33 2009 +

Issue #3166: Make long -> float (and int -> float) conversions
correctly rounded, using round-half-to-even.  This ensures that the
value of float(n) doesn't depend on whether we're using 15-bit digits
or 30-bit digits for Python longs.

--

Py_SET_ERRNO_ON_MATH_ERROR() and Py_SET_ERANGE_IF_OVERFLOW() were used in 
Objects/mathmodule.c in Python 2.5.


(1) The last call to Py_SET_ERRNO_ON_MATH_ERROR() was removed by in Python 2.6 
by:

commit 6f34109384f3a78d5f4f8bdd418a89caca19631e
Author: Christian Heimes 
Date:   Fri Apr 18 23:13:07 2008 +

I finally got the time to update and merge Mark's and my trunk-math branch. 
The patch is collaborated work of Mark Dickinson and me. It was mostly done a 
few months ago. The patch fixes a lot of loose ends and edge cases related to 
operations with NaN, INF, very small values and complex math.

The patch also adds acosh, asinh, atanh, log1p and copysign to all 
platforms. Finally it fixes differences between platforms like different 
results or exceptions for edge cases. Have fun :)


(2) The last call to Py_SET_ERANGE_IF_OVERFLOW() was removed in Python 2.4 by:

commit 77d9a3effa21b8987ceac26d67ad676e1c5afb49
Author: Hye-Shik Chang 
Date:   Mon Mar 22 08:43:55 2004 +

Patch #871657: Set EDOM for `nan' return values on FreeBSD and OpenBSD.
This fixes a problem that math.sqrt(-1) doesn't raise math.error.

--
components: C API
messages: 403473
nosy: vstinner
priority: normal
severity: normal
status: open
title: [C API] Remove Py_OVERFLOWED(), Py_SET_ERRNO_ON_MATH_ERROR(), 
Py_ADJUST_ERANGE1()
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com