summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* Revert gh-139075. The sumprod fix needs more work. (gh-139092)Raymond Hettinger2025-09-181-14/+15
|
* gh-139074: Fix missing high precision case in sumprod() (gh-139075)Raymond Hettinger2025-09-171-15/+14
|
* GH-137623: Use an AC decorator for docstring line length enforcement (#137690)Adam Turner2025-08-181-3/+6
|
* gh-135853: add `math.fmax` and `math.fmin` (#135888)Bénédikt Tran2025-07-121-0/+36
|
* gh-135853: add `math.signbit` (#135877)Bénédikt Tran2025-06-281-0/+18
|
* gh-135927: Fix MSVC Clatest C builds (GH-135935)Ken Jin2025-06-251-1/+1
|
* gh-132908: Add math.isnormal/issubnormal() functions (GH132935)Sergey B Kirpichev2025-06-021-0/+40
|
* gh-132876: workaround broken ldexp() on Windows 10 (#133135)Sergey B Kirpichev2025-05-261-0/+21
| | | | | | | | | * gh-132876: workaround broken ldexp() on Windows 10 ldexp() fails to round subnormal results before Windows 11, so hide their bug. Co-authored-by: Tim Peters <tim.peters@gmail.com>
* gh-133904: Fix `math.factorial` documentation (#133907)mkaraev2025-05-121-3/+1
| | | Co-authored-by: sobolevn <mail@sobolevn.me>
* gh-101410: Customize error messages for 1-arg math functions (#129497)Sergey B Kirpichev2025-04-221-17/+25
| | | | | | This also reverts loghelper() change in 75f59bb629 for integer input. The error message shouldn't include argument value here. Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-101410: Revert loghelper() change in 75f59bb for integer input (GH-132625)Sergey B Kirpichev2025-04-171-2/+4
|
* gh-131586: Avoid refcount contention in some "special" calls (#131588)Sam Gross2025-03-261-72/+22
| | | | | | | | | | In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to reference count contention on the returned function object becuase it doesn't use stackrefs. Refactor some of the callers to use `_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally. This fixes the scaling bottleneck in the "lookup_special" microbenchmark in `ftscalingbench.py`. However, the are still some uses of `_PyObject_LookupSpecial()` that need to be addressed in future PRs.
* gh-101410: support custom messages for domain errors in the math module ↵Sergey B Kirpichev2025-01-231-29/+66
| | | | | | | | | | | (#124299) This adds basic support to override default messages for domain errors in the math_1() helper. The sqrt(), atanh(), log2(), log10() and log() functions were modified as examples. New macro supports gradual changing of error messages in other 1-arg functions. Co-authored-by: CharlieZhao <zhaoyu_hit@qq.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* 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)