summaryrefslogtreecommitdiffstats
path: root/Modules/mathmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.8] bpo-39871: Fix possible SystemError in atan2, copysign and remainder ↵Mark Dickinson2020-03-141-1/+5
| | | | | | | | | | | | (GH-18806) (GH-18989) In math_2(), the first PyFloat_AsDouble() call should be checked for failure before the second call. Co-authored-by: Mark Dickinson <dickinsm@gmail.com>. (cherry picked from commit 5208b4b37953a406db0ed6a9db545c2948dde989) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* bpo-37691: Let math.dist() accept sequences and iterables for coordinates ↵Miss Islington (bot)2019-07-271-6/+36
| | | | | | | (GH-14975) (GH-14984) (cherry picked from commit 6b5f1b496f0b20144592b640b9c975df43a29eb0) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
* Fix some typos (GH-14435)Miss Islington (bot)2019-07-051-1/+1
| | | | | (cherry picked from commit f7d72e48fb235684e17668a1e5107e6b0dab7b80) Co-authored-by: Min ho Kim <minho42@gmail.com>
* Turn math.isqrt assertion into a comment to clarify its purpose. (GH-14131)Miss Islington (bot)2019-06-161-1/+1
| | | | | (cherry picked from commit 2dfeaa9222e2ed6b6e32faaf08e5b0f77318f0a7) Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* Simplify negativity checks in math.comb and math.perm. (GH-13870) (#14125)Miss Islington (bot)2019-06-161-10/+16
| | | | | (cherry picked from commit 45e0411eee023b21acf1615e995d26058d66c0f1) Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-37178: Allow a one argument form of math.perm() (GH-13905) (GH-13919)Miss Islington (bot)2019-06-081-2/+8
| | | | | (cherry picked from commit e119b3d136bd94d880bce4b382096f6de3f38062) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
* bpo-35431: Drop the k <= n requirement (GH-13798)Raymond Hettinger2019-06-041-15/+18
|
* bpo-37128: Add math.perm(). (GH-13731)Serhiy Storchaka2019-06-021-1/+129
|
* bpo-35431: Refactor math.comb() implementation. (GH-13725)Serhiy Storchaka2019-06-011-74/+81
| | | | | | | * Fixed some bugs. * Added support for index-likes objects. * Improved error messages. * Cleaned up and optimized the code. * Added more tests.
* bpo-35431: Implemented math.comb (GH-11414)Yash Aggarwal2019-06-011-0/+121
|
* bpo-36957: Speed up math.isqrt (#13405)Mark Dickinson2019-05-191-8/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add math.isqrt function computing the integer square root. * Code cleanup: remove redundant comments, rename some variables. * Tighten up code a bit more; use Py_XDECREF to simplify error handling. * Update Modules/mathmodule.c Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com> * Update Modules/mathmodule.c Use real argument clinic type instead of an alias Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com> * Add proof sketch * Updates from review. * Correct and expand documentation. * Fix bad reference handling on error; make some variables block-local; other tidying. * Style and consistency fixes. * Add missing error check; don't try to DECREF a NULL a * Simplify some error returns. * Another two test cases: - clarify that floats are rejected even if they happen to be squares of small integers - TypeError beats ValueError for a negative float * Add fast path for small inputs. Needs tests. * Speed up isqrt for n >= 2**64 as well; add extra tests. * Reduce number of test-cases to avoid dominating the run-time of test_math. * Don't perform unnecessary extra iterations when computing c_bit_length. * Abstract common uint64_t code out into a separate function. * Cleanup. * Add a missing Py_DECREF in an error branch. More cleanup. * Update Modules/mathmodule.c Add missing `static` declaration to helper function. Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com> * Add missing backtick.
* bpo-36957: Add _PyLong_Rshift() and _PyLong_Lshift(). (GH-13416)Serhiy Storchaka2019-05-191-23/+7
|
* bpo-36887: add math.isqrt (GH-13244)Mark Dickinson2019-05-181-0/+261
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add math.isqrt function computing the integer square root. * Code cleanup: remove redundant comments, rename some variables. * Tighten up code a bit more; use Py_XDECREF to simplify error handling. * Update Modules/mathmodule.c Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com> * Update Modules/mathmodule.c Use real argument clinic type instead of an alias Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com> * Add proof sketch * Updates from review. * Correct and expand documentation. * Fix bad reference handling on error; make some variables block-local; other tidying. * Style and consistency fixes. * Add missing error check; don't try to DECREF a NULL a * Simplify some error returns. * Another two test cases: - clarify that floats are rejected even if they happen to be squares of small integers - TypeError beats ValueError for a negative float * Documentation and markup improvements; thanks Serhiy for the suggestions! * Cleaner Misc/NEWS entry wording. * Clean up (with one fix) to the algorithm explanation and proof.
* bpo-36908: 'This module is always available' isn't helpful. (#13297)Ned Batchelder2019-05-171-2/+2
| | | | Makes the documentation of math and cmath module more helpful for the beginners.
* Rework integer overflow path in math.prod and add more tests (GH-11809)Pablo Galindo2019-03-091-5/+51
| | | | | The overflow check was relying on undefined behaviour as it was using the result of the multiplication to do the check, and once the overflow has already happened, any operation on the result is undefined behaviour. Some extra checks that exercise code paths related to this are also added.
* bpo-36106: Resolve sinpi name clash with libm (IEEE-754 violation). (GH-12027)Dima Pasechnik2019-02-261-4/+4
| | | | | | | | | The standard math library (libm) may follow IEEE-754 recommendation to include an implementation of sinPi(), i.e. sinPi(x):=sin(pi*x). And this triggers a name clash, found by FreeBSD developer Steve Kargl, who worken on putting sinpi into libm used on FreeBSD (it has to be named "sinpi", not "sinPi", cf. e.g. https://en.cppreference.com/w/c/experimental/fpext4).
* Fix division by 0 when checking for overflow in math.prod (GH-11808)Pablo Galindo2019-02-101-2/+2
|
* bpo-35606: Implement math.prod (GH-11359)Pablo Galindo2019-02-071-0/+167
|
* Move float conversion into a macro. Apply to fsum (GH-11698)Raymond Hettinger2019-01-301-49/+32
|
* Fast path for int inputs to math.dist() and math.hypot() (GH-11692)Raymond Hettinger2019-01-281-3/+24
|
* bpo-35719: Optimize multi-argument math functions. (GH-11527)Serhiy Storchaka2019-01-121-19/+18
| | | | | Use the fast call convention for math functions atan2(), copysign(), hypot() and remainder() and inline unpacking arguments. This sped up them by 1.3--2.5 times.
* bpo-34838: Use subclass_of for math.dist. (GH-9659)Ammar Askar2019-01-121-8/+3
| | | | | Argument clinic now generates fast inline code for positional parsing, so the manually implemented type check in math.dist can be removed.
* bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. ↵Zackery Spytz2018-12-071-3/+4
| | | | | | (GH-11015) Set MemoryError when appropriate, add missing failure checks, and fix some potential leaks.
* Fixing wording in comment. (GH-10425)Raymond Hettinger2018-11-091-1/+1
| | | | Since the n==1 case just returns *max*, it cannot be larger than the magnitude of the vector entry.
* Speed-up math.dist() by 30% (GH-9628)Raymond Hettinger2018-09-291-3/+8
|
* bpo-33083 - Make math.factorial reject arguments that are not int-like (GH-6149)Pablo Galindo2018-09-031-3/+9
| | | math.factorial() was accepting non-integral Decimal instances. This is inconsistent with the actual behaviour for floats, which are not accepted.
* Minor improvement to code clarity (GH-9036)Raymond Hettinger2018-09-021-1/+1
| | | Make it clear that the n==0 case is included. Otherwise, you have to know that max==0.0 whenever n==0.
* Simplify vector_norm() by eliminating special cases in the main loop (GH-9006)Raymond Hettinger2018-08-311-22/+18
| | | The *max* value is no longer treated as a special case in the main loop. Besides making the main loop simpler and branchless, this also lets us relax the input restriction of *vec* to contain only non-negative values.
* Improve commutativity of math.hypot() and math.dist() (GH-8984)Raymond Hettinger2018-08-291-13/+19
|
* Fast path for exact floats in math.hypot() and math.dist() (GH-8949)Raymond Hettinger2018-08-271-9/+21
|
* Minor code clean-up. Don't alter the input vector. Use variables instead. ↵Raymond Hettinger2018-08-121-4/+5
| | | | GH-8748
* Add more tests and assertions for math.hypot() and math.dist() (GH-8747)Raymond Hettinger2018-08-121-0/+1
|
* Factor-out common code. Also, optimize common cases by preallocating space ↵Raymond Hettinger2018-08-121-41/+56
| | | | | on the stack. GH-8738 Improves speed by 9 to 10ns per call.
* Replace straight addition with Kahan summation and move max to the end (GH-8727)Raymond Hettinger2018-08-111-20/+45
|
* bpo-33089: Add math.dist() for computing the Euclidean distance between two ↵Raymond Hettinger2018-07-311-0/+84
| | | | points (GH-8561)
* bpo-33089: Multidimensional math.hypot() (GH-8474)Raymond Hettinger2018-07-281-38/+63
|
* bpo-31338 (#3374)Barry Warsaw2017-09-151-2/+1
| | | | | | | * Add Py_UNREACHABLE() as an alias to abort(). * Use Py_UNREACHABLE() instead of assert(0) * Convert more unreachable code to use Py_UNREACHABLE() * Document Py_UNREACHABLE() and a few other macros.
* bpo-29962: add math.remainder (#950)Mark Dickinson2017-04-051-0/+103
| | | | | | | | | | | | | | * Implement math.remainder. * Fix markup for arguments; use double spaces after period. * Mark up function reference in what's new entry. * Add comment explaining the calculation in the final branch. * Fix out-of-order entry in whatsnew. * Add comment explaining why it's good enough to compare m with c, in spite of possible rounding error.
* bpo-29946: Fix "sqrtpi defined but not used" (#908)Louie Lu2017-03-301-1/+3
|
* bpo-26121: Revert to using the own implementations of lgamma and gamma on ↵Serhiy Storchaka2017-03-121-31/+0
| | | | all platforms. (#637)
* bpo-26121: Use C library implementation for math functions: (#515)Serhiy Storchaka2017-03-111-1/+45
| | | | | | | * bpo-26121: Use C library implementation for math functions: tgamma(), lgamma(), erf() and erfc(). * Don't use tgamma() and lgamma() from libc on OS X.
* Issue #29282: Backed out changeset b33012ef1417Mark Dickinson2017-01-211-42/+0
|
* Issue #29282: add fused multiply-add function, math.fma.Mark Dickinson2017-01-211-0/+42
|
* Issue #20186: Converted the math module to Argument Clinic.Serhiy Storchaka2017-01-191-247/+384
| | | | Patch by Tal Einat.
* Use _PyObject_CallNoArg()Victor Stinner2016-12-061-3/+3
| | | | | | | Replace: PyObject_CallFunctionObjArgs(callable, NULL) with: _PyObject_CallNoArg(callable)
* Backed out changeset b9c9691c72c5Victor Stinner2016-12-041-3/+3
| | | | | | Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like _PyObject_CallArg1() uses more stack memory than PyObject_CallFunctionObjArgs().
* Replace PyObject_CallFunctionObjArgs() with fastcallVictor Stinner2016-12-011-3/+3
| | | | | | | | | | | | | | * PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func) * PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg) PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires extra work to "parse" C arguments to build a C array of PyObject*. _PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate memory on the C stack. This change is part of the fastcall project. The change on listsort() is related to the issue #23507.
* Issue #27895: Spelling fixes (Contributed by Ville Skyttä).Raymond Hettinger2016-08-301-1/+1
|
* Issue #12345: Add mathemathcal constant tau to math and cmath.Guido van Rossum2016-08-151-0/+1
| | | | Patch by Lisa Roach. See also PEP 628.
* Issue #26512: Merge rounding doc from 3.5Martin Panter2016-05-081-4/+4
|\