summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-122943: Rework support of var-positional parameter in Argument Clinic ↵Serhiy Storchaka2024-11-071-20/+23
| | | | | | | | | | | | | | | | | | (GH-122945) Move creation of a tuple for var-positional parameter out of _PyArg_UnpackKeywordsWithVararg(). Merge _PyArg_UnpackKeywordsWithVararg() with _PyArg_UnpackKeywords(). Add a new parameter in _PyArg_UnpackKeywords(). The "parameters" and "converters" attributes of ParseArgsCodeGen no longer contain the var-positional parameter. It is now available as the "varpos" attribute. Optimize code generation for var-positional parameter and reuse the same generating code for functions with and without keyword parameters. Add special converters for var-positional parameter. "tuple" represents it as a Python tuple and "array" represents it as a continuous array of PyObject*. "object" is a temporary alias of "tuple".
* gh-119793: Prefer `map(..., strict=True)` over starmap/zip in examples (#126407)Lukas Geiger2024-11-051-2/+2
|
* gh-120026: soft deprecate Py_HUGE_VAL macro (#120027)Sergey B Kirpichev2024-11-011-7/+7
| | | Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
* gh-101123: Adapt vararg functions in the math module to Argument Clinic ↵Sergey B Kirpichev2024-10-311-36/+44
| | | | | | (#126235) This implicitly fixes the math.hypot signature, which was previously incomprehensible to inspect.signature().
* gh-123497: New limit for Python integers on 64-bit platforms (GH-123724)Serhiy Storchaka2024-09-291-13/+12
| | | | | | | | | | | Instead of be limited just by the size of addressable memory (2**63 bytes), Python integers are now also limited by the number of bits, so the number of bit now always fit in a 64-bit integer. Both limits are much larger than what might be available in practice, so it doesn't affect users. _PyLong_NumBits() and _PyLong_Frexp() are now always successful.
* gh-123836: workaround fmod(x, y) bug on Windows (#124171)Sergey B Kirpichev2024-09-171-0/+9
| | | | | | | | | | | | | | | | | | Buildbot failure on Windows 10 with MSC v.1916 64 bit (AMD64): FAIL: testFmod (test.test_math.MathTests.testFmod) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 605, in testFmod self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0) ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_math.py", line 258, in ftest self.fail("{}: {}".format(name, failure)) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: fmod(-10, 1): expected -0.0, got 0.0 (zero has wrong sign) Here Windows loose sign of the result; if y is nonzero, the result should have the same sign as x. This amends commit 28aea5d07d.
* gh-121485: Always use 64-bit integers for integers bits count (GH-121486)Serhiy Storchaka2024-08-301-4/+4
| | | | | Use 64-bit integers instead of platform specific size_t or Py_ssize_t to represent the number of bits in Python integer.
* gh-122681: remove m_atan2()/c_atan2() helpers (#122715)Sergey B Kirpichev2024-08-171-1/+1
|
* gh-122681: merge m_atan2() and c_atan2() helper functions (#122682)Sergey B Kirpichev2024-08-061-37/+0
|
* gh-121905: Consistently use "floating-point" instead of "floating point" ↵Serhiy Storchaka2024-07-191-7/+7
| | | | (GH-121907)
* gh-119613: Use C99+ functions instead of Py_IS_NAN/INFINITY/FINITE (#119619)Sergey B Kirpichev2024-05-291-70/+70
|
* 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
|