summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-118671: Updated dead ActiveState links (#118730)trag1c2024-05-081-1/+1
| | | | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+1
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-73468: Add math.fma() function (#116667)Victor Stinner2024-03-171-0/+43
| | | | | | Added new math.fma() function, wrapping C99's ``fma()`` operation: fused multiply-add function. Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
* gh-111417: Remove unused code block in math.trunc() and round() (GH-111454)Jason Zhang2024-02-031-5/+0
| | | _PyObject_LookupSpecial() now ensures that the type is ready.
* gh-114569: Use PyMem_* APIs for most non-PyObject uses (#114574)Erlend E. Aasland2024-01-261-6/+6
| | | Fix usage in Modules, Objects, and Parser subdirectories.
* gh-111139: Optimize math.gcd(int, int) (#113887)Victor Stinner2024-01-101-5/+9
| | | | | | | | | | | | | Add a fast-path for the common case. Benchmark: python -m pyperf timeit \ -s 'import math; gcd=math.gcd; x=2*3; y=3*5' \ 'gcd(x,y)' Result: 1.07x faster (-3.4 ns) Mean +- std dev: 52.6 ns +- 4.0 ns -> 49.2 ns +- 0.4 ns: 1.07x faster
* gh-111342: fix typo in math.sumprod (GH-111416)Sergey B Kirpichev2023-10-281-1/+1
|
* gh-110489: Optimise math.ceil for known exact float (#108801)Shantanu2023-10-061-7/+9
| | | | This matches a similar optimisation done for math.floor in https://github.com/python/cpython/pull/21072
* gh-102837: improve test coverage for math module (#102523)Sergey B Kirpichev2023-09-031-10/+7
| | | | | | | | - input checks for math_1(L989), math_1a(L1023), math_2(L1064,L1071), hypot(L2682), log(L2307), ldexp(L2168), ceil(L1165), floor(L1236,L1239) and dist(L2587,L2588,L2628). - drop inaccessible "if" branch (L3518) in perm_comb_small() - improve fsum coverage for exceptional cases (L1433,L1438,L1451,L1497), ditto fmod(L2378) - rewrite modf to fix inaccessible case(L2229), ditto for pow(L2988) (all line numbers are wrt the main branch at 5e6661bce9)
* gh-106320: Remove private AC converter functions (#108505)Victor Stinner2023-08-261-0/+1
| | | | | | | | | | | | | | Move these private functions to the internal C API (pycore_abstract.h): * _Py_convert_optional_to_ssize_t() * _PyNumber_Index() Argument Clinic now emits #include "pycore_abstract.h" when these functions are used. The parser of the c-analyzer tool now uses a list of files which use the limited C API, rather than a list of files using the internal C API.
* gh-86493: Fix possible leaks in some modules initialization (GH-106768)Serhiy Storchaka2023-07-181-5/+5
| | | | Fix _ssl, _stat, _testinternalcapi, _threadmodule, cmath, math, posix, time.
* gh-94673: Ensure subtypes are readied only once in math.trunc() (gh-105465)neonene2023-06-071-1/+1
| | | Fixes a typo in d2e2e53.
* gh-94906: Support multiple steps in math.nextafter (#103881)Matthias Görgens2023-05-191-4/+105
| | | | | | | This PR updates `math.nextafter` to add a new `steps` argument. The behaviour is as though `math.nextafter` had been called `steps` times in succession. --------- Co-authored-by: Mark Dickinson <mdickinson@enthought.com>
* gh-104263: Rely on Py_NAN and introduce Py_INFINITY (GH-104202)Sebastian Berg2023-05-101-35/+4
| | | | | | | | | | This PR removes `_Py_dg_stdnan` and `_Py_dg_infinity` in favour of using the standard `NAN` and `INFINITY` macros provided by C99. This change has the side-effect of fixing a bug on MIPS where the hard-coded value used by `_Py_dg_stdnan` gave a signalling NaN rather than a quiet NaN. --------- Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* gh-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-051-0/+1
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
* Fix typo in math.log docstring (#103943)Wes Turner2023-04-281-1/+1
|
* gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)Eric Snow2023-04-271-1/+1
| | | There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
* GH-101291: Rearrange the size bits in PyLongObject (GH-102464)Mark Shannon2023-03-221-9/+10
| | | | | | | | | | * Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
* gh-102839: remove AC for math.log (GH-102863)Sergey B Kirpichev2023-03-211-21/+14
|
* Add more comments to hypot() (GH-102817)Raymond Hettinger2023-03-181-18/+12
|
* Simplify and improve accuracy for subnormals in hypot() (GH-102785)Raymond Hettinger2023-03-171-35/+28
|
* Simplify and speed-up math.hypot() and math.dist() (GH-102734)Raymond Hettinger2023-03-151-154/+139
|
* gh-101678: Merge math_1_to_whatever() and math_1() (#101730)Sergey B Kirpichev2023-02-091-10/+2
| | | | | | `math_1_to_whatever()` is no longer useful, since all existing uses of it convert to `float`. Earlier versions of Python used `math_1_to_whatever` with an integer target; see gh-16991 for the PR where that use was removed.
* gh-101678: refactor the math module to use special functions from c11 ↵Sergey B Kirpichev2023-02-091-182/+5
| | | | | | | (GH-101679) Shouldn't affect users, hence no news. Automerge-Triggered-By: GH:mdickinson
* Revert "gh-89381: Fix invalid signatures of math/cmath.log (#101404)" (#101580)Mark Dickinson2023-02-051-6/+8
| | | This reverts commit 0ef92d979311ba82d4c41b22ef38e12e1b08b13d.
* GH-100485: Create an alternative code path when an accurate fma() ↵Raymond Hettinger2023-02-041-0/+43
| | | | implementation is not available (#101567)
* gh-89381: Fix invalid signatures of math/cmath.log (#101404)Sergey B Kirpichev2023-01-291-8/+6
|
* GH-100485: Add extended accuracy test. Switch to faster fma() based ↵Raymond Hettinger2023-01-281-36/+17
| | | | variant. GH-101383)
* Speed-up and improve accuracy with Rump Algorithms (3.1) and (5.10) (GH-101366)Raymond Hettinger2023-01-271-21/+16
|
* Sumprod(): Update citation. Reorder functions. Add final twosum() call. ↵Raymond Hettinger2023-01-221-38/+21
| | | | Improve comments. (#101249)
* gh-100873: Fix "‘lo’ may be used uninitialized in this function" warning ↵Nikita Sobolev2023-01-091-1/+1
| | | | in `mathmodule.c` (#100881)
* gh-100833: Remove 'volatile' qualifiers in fsum algorithm (#100845)Mark Dickinson2023-01-081-22/+22
| | | | | | | This PR removes the `volatile` qualifier on various intermediate quantities in the `math.fsum` implementation, and updates the notes preceding the algorithm accordingly (as well as fixing some of the exsting notes). See the linked issue #100833 for discussion.
* GH-100485: Tweaks to sumprod() (GH-100857)Raymond Hettinger2023-01-081-25/+34
|
* GH-100485: Convert from Fast2Sum to 2Sum (GH-100836)Raymond Hettinger2023-01-081-13/+16
|
* GH-100485: Add math.sumprod() (GH-100677)Raymond Hettinger2023-01-071-0/+325
|
* gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)Victor Stinner2022-11-231-6/+3
| | | Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
* gh-99537: Use Py_SETREF() function in C code (#99656)Victor Stinner2022-11-221-4/+2
| | | | | | | | | | | | | | | Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
* gh-99300: Use Py_NewRef() in Modules/ directory (#99469)Victor Stinner2022-11-141-4/+2
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
* GH-98897: fix memory leak if `math.dist` raises exception (GH-98898)Kumar Aditya2022-11-011-3/+3
|
* Remove usage of _Py_IDENTIFIER from math module (#93739)Dong-hee Na2022-06-121-9/+55
|
* remove redundant argument to log_helper (GH-93440)Pieter Eendebak2022-06-031-5/+5
|
* gh-91320: Use _PyCFunction_CAST() (#92251)Victor Stinner2022-05-031-6/+6
| | | | | | | | | | Replace "(PyCFunction)(void(*)(void))func" cast with _PyCFunction_CAST(func). Change generated by the command: sed -i -e \ 's!(PyCFunction)(void(\*)(void)) *\([A-Za-z0-9_]\+\)!_PyCFunction_CAST(\1)!g' \ $(find -name "*.c")
* Change parameter name from *x* for reals to *n* for integers. (GH-32377)Raymond Hettinger2022-04-061-3/+3
|
* bpo-46656: Remove Py_NO_NAN macro (GH-31160)Victor Stinner2022-02-251-2/+2
| | | | Building Python now requires support for floating point Not-a-Number (NaN): remove the Py_NO_NAN macro.
* bpo-45412: Add _PY_SHORT_FLOAT_REPR macro (GH-31171)Victor Stinner2022-02-231-4/+5
| | | | | | | | | | Remove the HAVE_PY_SET_53BIT_PRECISION macro (moved to the internal C API). * Move HAVE_PY_SET_53BIT_PRECISION macro to pycore_pymath.h. * Replace PY_NO_SHORT_FLOAT_REPR macro with _PY_SHORT_FLOAT_REPR macro which is always defined. gcc -Wundef emits a warning when using _PY_SHORT_FLOAT_REPR but the macro is not defined, if pycore_pymath.h include was forgotten.
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-46258: Streamline isqrt fast path (#30333)Mark Dickinson2022-01-151-14/+43
|
* bpo-37295: Use constant-time comb() and perm() for larger n depending on k ↵Serhiy Storchaka2022-01-091-130/+186
| | | | (GH-30305)
* bpo-37295: More direct computation of power-of-two factor in math.comb ↵Mark Dickinson2021-12-311-7/+25
| | | | | (GH-30313) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-37295: Speed up math.comb(n, k) for 0 <= k <= n <= 67 (GH-30275)Mark Dickinson2021-12-281-0/+89
|