summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* bpo-46018: Ensure that math.expm1 does not raise on underflow (GH-29997)Steve Dower2021-12-091-2/+6
|
* bpo-37295: Optimize math.comb() and math.perm() (GH-29090)Serhiy Storchaka2021-12-051-93/+192
| | | | | | | | For very large numbers use divide-and-conquer algorithm for getting benefit of Karatsuba multiplication of large numbers. Do calculations completely in C unsigned long long instead of Python integers if possible.
* bpo-45917: Add math.exp2() method - return 2 raised to the power of x (GH-29829)Gideon2021-11-291-0/+4
| | | Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-45548: Remove _math.c workarounds for pre-C99 libm (GH-29179)Christian Heimes2021-10-251-4/+7
| | | | | | | | | | | | | The :mod:`math` and :mod:`cmath` implementation now require a C99 compatible ``libm`` and no longer ship with workarounds for missing acosh, asinh, expm1, and log1p functions. The changeset also removes ``_math.c`` and moves the last remaining workaround into ``_math.h``. This simplifies static builds with ``Modules/Setup`` and resolves symbol conflicts. Co-authored-by: Mark Dickinson <mdickinson@enthought.com> Co-authored-by: Brett Cannon <brett@python.org> Signed-off-by: Christian Heimes <christian@python.org>
* bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)Christian Heimes2021-10-221-0/+4
| | | | | | | | | | | | | | setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every module defines the macro before #include "Python.h" unless Py_BUILD_CORE_BUILTIN is already defined. Py_BUILD_CORE_BUILTIN is defined for every module that is built by Modules/Setup. The PR also simplifies Modules/Setup. Makefile and makesetup already define Py_BUILD_CORE_BUILTIN and include Modules/internal for us. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)Victor Stinner2021-10-121-1/+2
| | | | | | | * Move _PyObject_CallNoArgs() to pycore_call.h (internal C API). * _ssl, _sqlite and _testcapi extensions now call the public PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs(). * _lsprof extension is now built with Py_BUILD_CORE_MODULE macro defined to get access to internal _PyObject_CallNoArgs().
* bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)Victor Stinner2021-10-111-3/+3
| | | | | Fix typo in the private _PyObject_CallNoArg() function name: rename it to _PyObject_CallNoArgs() to be consistent with the public function PyObject_CallNoArgs().
* bpo-35606: Fix math.prod tests using 'start' as keyword parameter (GH-28595)Pablo Galindo Salgado2021-09-281-8/+3
|
* bpo-44339: Fix math.pow corner case to comply with IEEE 754 (GH-26606)Mark Dickinson2021-06-121-2/+0
| | | Change the behaviour of `math.pow(0.0, -math.inf)` and `math.pow(-0.0, -math.inf)` to return positive infinity instead of raising `ValueError`. This makes `math.pow` consistent with the built-in `pow` (and the `**` operator) for this particular special case, and brings the `math.pow` special-case handling into compliance with IEEE 754.
* bpo-44357:Add `math.cbrt()` function: Cube Root (GH-26622)Ajith Ramachandran2021-06-101-0/+4
| | | | | | * Add math.cbrt() function: Cube Root Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-42161: mathmodule.c: move _PyLong_GetOne() loop invariant (GH-26391)Victor Stinner2021-05-261-8/+12
| | | | | | | | | Move _PyLong_GetZero() and _PyLong_GetOne() loop invariants outside loops in functions: * math.comb() * math.gcd() * math.lcm() * math.perm()
* missing multiply symbol in the documentation (GH-24686)Alperen Serkan Aksöz2021-03-031-1/+1
|
* bpo-42323: Fix math.nextafter() on AIX (GH-24381)Victor Stinner2021-01-291-2/+2
| | | math_nextafter_impl() must return a Python object, not a C double.
* bpo-42323: Fix math.nextafter() for NaN on AIX (GH-24265)Victor Stinner2021-01-201-0/+6
|
* bpo-42161: Modules/ uses _PyLong_GetZero() and _PyLong_GetOne() (GH-22998)Victor Stinner2020-10-271-5/+6
| | | | | | Use _PyLong_GetZero() and _PyLong_GetOne() in Modules/ directory. _cursesmodule.c and zoneinfo.c are now built with Py_BUILD_CORE_MODULE macro defined.
* Update link to supporting references (GH-22488)Raymond Hettinger2020-10-021-1/+1
|
* bpo-41513: Improve order of adding fractional values. Improve variable ↵Raymond Hettinger2020-09-231-12/+12
| | | | names. (GH-22368)
* Make fractional value accumulation consistent inside and outside the loop. ↵Raymond Hettinger2020-09-191-5/+4
| | | | (GH-22315)
* bpo-41513: Add docs and tests for hypot() (GH-22238)Raymond Hettinger2020-09-141-7/+7
|
* bpo-41513: Expand comments and add references for a better understanding ↵Raymond Hettinger2020-09-061-5/+21
| | | | (GH-22123)
* Improve hypot() accuracy with three separate accumulators (GH-22032)Raymond Hettinger2020-09-021-4/+4
|
* Further improve accuracy of math.hypot() (GH-22013)Raymond Hettinger2020-08-301-3/+8
|