Commit Graph

124 Commits

Author SHA1 Message Date
Andre Delfino e8a2076e14
Revert "Fix all Python Cookbook links (#22205)" (GH-22424)
This commit reverts commit ac0333e1e1 as the original links are working again and they provide extended features such as comments and alternative versions.
2020-09-27 01:47:25 +01:00
Raymond Hettinger bc6b7fa6d7
bpo-41513: Add accuracy tests for math.hypot() (GH-22327) 2020-09-20 21:47:56 -07:00
Andre Delfino ac0333e1e1
Fix all Python Cookbook links (#22205) 2020-09-15 21:13:26 +01:00
Raymond Hettinger 95a8a0e01d
bpo-41513: Remove broken tests that fail on Gentoo (GH-22249) 2020-09-14 17:13:49 -07:00
Raymond Hettinger 457d4e97de
bpo-41513: Add docs and tests for hypot() (GH-22238) 2020-09-13 23:33:41 -07:00
Raymond Hettinger fff3c28052
bpo-41513: Improve speed and accuracy of math.hypot() (GH-21803) 2020-08-15 19:38:19 -07:00
Serhiy Storchaka 578c3955e0
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
Only __index__ should be used to make integer conversions lossless.
2020-05-26 18:43:38 +03:00
Zackery Spytz 5208b4b379
bpo-39871: Fix possible SystemError in atan2, copysign and remainder (GH-18806)
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>
2020-03-14 10:45:32 +00:00
Serhiy Storchaka 559e7f165a
bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments. (GH-18604)
* bpo-39648: Expand math.gcd() and math.lcm() to handle multiple arguments.

* Simplify fast path.

* Difine lcm() without arguments returning 1.

* Apply suggestions from code review

Co-Authored-By: Mark Dickinson <dickinsm@gmail.com>

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
2020-02-23 11:21:29 +00:00
ananthan-123 f2ee21d858
bpo-39479:Add math.lcm() function: Least Common Multiple (#18547)
* Update math.rst

* Update math.rst

* updated whats new

* Update test_math.py

* Update mathmodule.c

* Update mathmodule.c.h

* Update ACKS

* 📜🤖 Added by blurb_it.

* Update 3.9.rst

* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst

* Update math.rst

* Update 2020-02-18-12-37-16.bpo-39479.j3UcCq.rst

* Update test_math.py

* Update ACKS

* Update mathmodule.c.h

* Update mathmodule.c

* Update mathmodule.c.h

* Update mathmodule.c.h

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-02-19 18:21:37 +00:00
Victor Stinner 59e2d26b25
Move test_math tests (GH-18098)
testPerm() and testComb() belong to MathTests, not to IsCloseTests().

test_nextafter() and test_ulp() now use assertIsNaN().
2020-01-21 12:48:16 +01:00
Victor Stinner 85ead4fc62
bpo-39396: Fix math.nextafter(-0.0, +0.0) on AIX 7.1 (GH-18094)
Move also math.nextafter() on math.ulp() tests from IsCloseTests to
MathTests.
2020-01-21 11:14:10 +01:00
Victor Stinner 0b2ab21956
bpo-39310: Add math.ulp(x) (GH-17965)
Add math.ulp(): return the value of the least significant bit
of a float.
2020-01-13 12:44:35 +01:00
Victor Stinner 100fafcf20
bpo-39288: Add math.nextafter(x, y) (GH-17937)
Return the next floating-point value after x towards y.
2020-01-12 02:15:42 +01:00
Mark Dickinson bba873e633
bpo-38992: avoid fsum test failure from constant-folding (GH-17513)
* Issue 38992: avoid fsum test failure

* Add NEWS entry
2019-12-09 08:36:34 -06:00
Serhiy Storchaka 5fd5cb8d85
bpo-38639: Optimize floor(), ceil() and trunc() for floats. (GH-16991) 2019-11-16 18:00:57 +02:00
Raymond Hettinger 6b5f1b496f
bpo-37691: Let math.dist() accept sequences and iterables for coordinates (GH-14975) 2019-07-27 14:04:29 -07:00
Min ho Kim 96e12d5f4f Fix typos in docs, comments and test assert messages (#14872) 2019-07-21 16:12:33 -04:00
Victor Stinner 8f4ef3b019
Remove unused imports in tests (GH-14518) 2019-07-01 18:28:25 +02:00
Paul Monson f355069a33 bpo-36511: Add buildbot scripts and fix tests for Windows ARM32 buildbot (GH-13454) 2019-06-19 13:09:54 -07:00
Serhiy Storchaka 1b8a46d597
bpo-35431: Test math.comb() and math.perm() for OverflowError only on CPython. (GH-14146)
Other implementation can raise MemoryError, but it can takes hours.
2019-06-17 16:58:32 +03:00
Serhiy Storchaka 231aad3849
bpo-37315: Deprecate accepting floats in math.factorial(). (GH-14147) 2019-06-17 16:57:27 +03:00
Raymond Hettinger e119b3d136
bpo-37178: Allow a one argument form of math.perm() (GH-13905) 2019-06-08 08:58:11 -07:00
Raymond Hettinger 963eb0f473
bpo-35431: Drop the k <= n requirement (GH-13798) 2019-06-04 01:23:06 -07:00
Serhiy Storchaka 5ae299ac78
bpo-37128: Add math.perm(). (GH-13731) 2019-06-02 11:16:49 +03:00
Serhiy Storchaka 2b843ac0ae
bpo-35431: Refactor math.comb() implementation. (GH-13725)
* Fixed some bugs.
* Added support for index-likes objects.
* Improved error messages.
* Cleaned up and optimized the code.
* Added more tests.
2019-06-01 22:09:02 +03:00
Yash Aggarwal 4a686504eb bpo-35431: Implemented math.comb (GH-11414) 2019-06-01 00:21:27 -07:00
Mark Dickinson 5c08ce9bf7
bpo-36957: Speed up math.isqrt (#13405)
* 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.
2019-05-19 17:51:56 +01:00
Mark Dickinson 73934b9da0
bpo-36887: add math.isqrt (GH-13244)
* 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.
2019-05-18 12:29:50 +01:00
Pablo Galindo 0411411c6b
Rework integer overflow path in math.prod and add more tests (GH-11809)
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.
2019-03-09 19:18:08 +00:00
Pablo Galindo 4207907c2b
Fix division by 0 when checking for overflow in math.prod (GH-11808) 2019-02-10 19:56:58 +00:00
Pablo Galindo bc09851586 bpo-35606: Implement math.prod (GH-11359) 2019-02-06 23:04:02 -08:00
Raymond Hettinger 808180c206
Fast path for int inputs to math.dist() and math.hypot() (GH-11692) 2019-01-28 13:59:56 -08:00
Ammar Askar cb08a71c5c bpo-34838: Use subclass_of for math.dist. (GH-9659)
Argument clinic now generates fast inline code for
positional parsing, so the manually implemented type
check in math.dist can be removed.
2019-01-12 08:23:41 +02:00
Benjamin Peterson 865c17fb28
closes bpo-34640: Remove the TANH_PRESERVES_ZERO_SIGN configure check. (GH-9206) 2018-09-12 06:51:18 -07:00
Pablo Galindo e9ba3705de
bpo-33083 - Make math.factorial reject arguments that are not int-like (GH-6149)
math.factorial() was accepting non-integral Decimal instances. This is inconsistent with the actual behaviour for floats, which are not accepted.
2018-09-03 22:20:06 +01:00
Raymond Hettinger 00414597b4
Add more tests and assertions for math.hypot() and math.dist() (GH-8747) 2018-08-12 12:15:23 -07:00
Raymond Hettinger 9c18b1ae52
bpo-33089: Add math.dist() for computing the Euclidean distance between two points (GH-8561) 2018-07-31 00:45:49 -07:00
Raymond Hettinger c6dabe37e3
bpo-33089: Multidimensional math.hypot() (GH-8474) 2018-07-28 07:48:04 -07:00
Mike 53f7a7c281 bpo-32297: Few misspellings found in Python source code comments. (#4803)
* Fix multiple typos in code comments

* Add spacing in comments (test_logging.py, test_math.py)

* Fix spaces at the beginning of comments in test_logging.py
2017-12-14 13:04:53 +02:00
Mark Dickinson a0ce375e10 bpo-29962: add math.remainder (#950)
* 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.
2017-04-05 18:34:27 +01:00
Mark Dickinson 5e65cd39df Issue #29282: Backed out changeset b33012ef1417 2017-01-21 13:10:52 +00:00
Mark Dickinson d1b230e48b Issue #29282: add fused multiply-add function, math.fma. 2017-01-21 12:35:30 +00:00
Mark Dickinson 31ba1c3de8 Issue #27427: Additional tests for the math module. Thanks Francisco Couzo. 2016-09-04 12:29:14 +01:00
Mark Dickinson 85746542ea Issue #27953: skip failing math and cmath tests for tan on OS X 10.4. 2016-09-04 09:58:51 +01:00
Mark Dickinson 96f774d824 Issue #26040: Improve test_math and test_cmath coverage and rigour. Thanks Jeff Allen. 2016-09-03 19:30:22 +01:00
Guido van Rossum 0a891d70de Issue #12345: Add mathemathcal constant tau to math and cmath.
Patch by Lisa Roach. See also PEP 628.
2016-08-15 09:12:52 -07:00
Martin Panter 8bde911115 Issue #27626: Merge spelling fixes from 3.5 2016-07-28 01:30:58 +00:00
Martin Panter eb9957065a Issue #27626: Spelling fixes in docs, comments and internal names
Based on patch by Ville Skyttä.
2016-07-28 01:11:04 +00:00
Serhiy Storchaka e437a10d15 Issue #23277: Remove unused imports in tests. 2016-04-24 21:41:02 +03:00