Commit Graph

195 Commits

Author SHA1 Message Date
Raymond Hettinger 216aaaa056 Fixing wording in comment. (GH-10425)
Since the n==1 case just returns *max*, it cannot be larger
than the magnitude of the vector entry.
2018-11-09 01:06:02 -08:00
Raymond Hettinger df8101517a
Speed-up math.dist() by 30% (GH-9628) 2018-09-29 14:30:38 -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 f326714426
Minor improvement to code clarity (GH-9036)
Make it clear that the n==0 case is included. Otherwise, you have to know that max==0.0 whenever n==0.
2018-09-02 13:34:21 -07:00
Raymond Hettinger 745c0f3980
Simplify vector_norm() by eliminating special cases in the main loop (GH-9006)
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.
2018-08-31 11:22:13 -07:00
Raymond Hettinger 21786f5186
Improve commutativity of math.hypot() and math.dist() (GH-8984) 2018-08-28 22:47:24 -07:00
Raymond Hettinger 74734f73ca
Fast path for exact floats in math.hypot() and math.dist() (GH-8949) 2018-08-26 19:38:31 -05:00
Raymond Hettinger a47f394af8
Minor code clean-up. Don't alter the input vector. Use variables instead. GH-8748 2018-08-12 14:18:56 -07: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 c630e10440
Factor-out common code. Also, optimize common cases by preallocating space on the stack. GH-8738
Improves speed by 9 to 10ns per call.
2018-08-11 18:39:05 -07:00
Raymond Hettinger 1399074535
Replace straight addition with Kahan summation and move max to the end (GH-8727) 2018-08-11 11:26:36 -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
Barry Warsaw b2e5794870 bpo-31338 (#3374)
* 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.
2017-09-14 18:13:16 -07: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
Louie Lu 7a26464c64 bpo-29946: Fix "sqrtpi defined but not used" (#908) 2017-03-30 20:05:10 +03:00
Serhiy Storchaka 4125e5c60e bpo-26121: Revert to using the own implementations of lgamma and gamma on all platforms. (#637) 2017-03-12 14:08:06 +02:00
Serhiy Storchaka 97553fdf9d bpo-26121: Use C library implementation for math functions: (#515)
* 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.
2017-03-11 21:37:16 +00: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
Serhiy Storchaka c9ea933586 Issue #20186: Converted the math module to Argument Clinic.
Patch by Tal Einat.
2017-01-19 18:13:09 +02:00
Victor Stinner f17c3de263 Use _PyObject_CallNoArg()
Replace:
    PyObject_CallFunctionObjArgs(callable, NULL)
with:
    _PyObject_CallNoArg(callable)
2016-12-06 18:46:19 +01:00
Victor Stinner de4ae3d486 Backed out changeset b9c9691c72c5
Issue #28858: The change b9c9691c72c5 introduced a regression. It seems like
_PyObject_CallArg1() uses more stack memory than
PyObject_CallFunctionObjArgs().
2016-12-04 22:59:09 +01:00
Victor Stinner 27580c1fb5 Replace PyObject_CallFunctionObjArgs() with fastcall
* 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.
2016-12-01 14:43:22 +01:00
Raymond Hettinger 15f44ab043 Issue #27895: Spelling fixes (Contributed by Ville Skyttä). 2016-08-30 10:47:49 -07: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 18933ed6ab Issue #26512: Merge rounding doc from 3.5 2016-05-08 12:34:58 +00:00
Martin Panter 129fe04d4d Issue #26512: Clarify Integral; tidy up table of rounding functions
Based on patch by Julien.
2016-05-08 12:22:37 +00:00
Berker Peksag a2570626c8 Issue #26898: Fix typo in math.isclose() docstring
Patch by Marco Buttu.
2016-05-01 11:27:59 +03:00
Berker Peksag d6e6f8b829 Issue #26898: Fix typo in math.isclose() docstring
Patch by Marco Buttu.
2016-05-01 11:27:37 +03:00
Brett Cannon 2f1a0b6ad5 Merge for issue #26114 2016-01-15 09:39:06 -08:00
Brett Cannon 45adb3100b Issue #26114: Remove a reference to 'Numerical Recipes'.
While no copyright violation occurred, the license which
'Numerical Recipes' operates under is not amenable to Python,
so to prevent confusion it's easier to simply remove its mention.
2016-01-15 09:38:24 -08:00
Serhiy Storchaka ef1585eb9a Issue #25923: Added more const qualifiers to signatures of static and private functions. 2015-12-25 20:01:53 +02:00
Tal Einat d5519ed7f4 Issue #19543: Implementation of isclose as per PEP 485
For details, see:
PEP 0485 -- A Function for testing approximate equality

Functions added: math.isclose() and cmath.isclose().

Original code by Chris Barker. Patch by Tal Einat.
2015-05-31 22:05:00 +03:00
Serhiy Storchaka 48e47aaa28 Issue #22486: Added the math.gcd() function. The fractions.gcd() function now is
deprecated.  Based on patch by Mark Dickinson.
2015-05-13 00:19:51 +03:00
Serhiy Storchaka c2ccce791c Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
Added few tests for __truediv__, __floordiv__ and __matmul__.
2015-03-12 22:01:30 +02:00
Serhiy Storchaka a60c2fe480 Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
2015-03-12 21:56:08 +02:00
Mark Dickinson cc8617b93a Issue #21092: Merge from 3.4. 2015-01-11 13:22:44 +00:00
Mark Dickinson dfe0b2326b Issue #21902: Replace incorrect 'hyperbolic arc sine' (etc.) with 'inverse hyperbolic sine' (etc.). Remove meaningless reference to radians. 2015-01-11 13:08:05 +00:00
Mark Dickinson a5d0c7c2fd Issue #23185: add math.inf and math.nan constants. 2015-01-11 11:55:29 +00:00
Victor Stinner 049e509a9f Issue #22207: Fix "comparison between signed and unsigned integers" warning in
test checking for integer overflow on Py_ssize_t type: cast explicitly to
size_t.
2014-08-17 22:20:00 +02:00
Mark Dickinson 5990d2864c Issue #20539: Improve math.factorial error messages and types for large inputs.
- Better message for the OverflowError in large positive inputs.
- Changed exception type from OverflowError to ValueError for large negative inputs.
2014-04-10 09:29:39 -04:00
Andrew Kuchling 3137885c36 #12211: remove paragraph about NaNs 2014-02-16 12:09:35 -05:00
Andrew Kuchling 8cb1ec3274 #12211: clarify math.copysign() documentation and docstring 2014-02-16 11:11:25 -05:00
Serhiy Storchaka 9594942716 Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 19:40:23 +03:00
Mark Dickinson 039e0cdc28 Issue #16305: Merge fix from 3.2. 2012-10-25 10:47:46 +01:00
Mark Dickinson 76464494bc Fix math.factorial KeyboardInterrupt segfault. Thanks Amaury for report and diagnosis. 2012-10-25 10:46:28 +01:00
Benjamin Peterson 7d74b70e51 merge 3.2 2012-03-13 16:13:35 -05:00
Benjamin Peterson 2354a7593f fix indentation 2012-03-13 16:13:09 -05:00
Benjamin Peterson ce79852077 use the static identifier api for looking up special methods
I had to move the static identifier code from unicodeobject.h to object.h in
order for this to work.
2012-01-22 11:24:29 -05:00