You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2797 lines
84 KiB

36 years ago
30 years ago
36 years ago
30 years ago
36 years ago
14 years ago
36 years ago
30 years ago
36 years ago
36 years ago
36 years ago
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines Mention issue6972 in extractall docs about overwriting things outside of the supplied path. ........ r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line Wording fix ........ r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line Fix narkup ........ r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line Document 'skip' parameter to constructor ........ r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line Note side benefit of socket.create_connection() ........ r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line Reword sentence ........ r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line Use standard comma punctuation; reword some sentences in the docs ........ r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line Backport r73983: Document the thousands separator. ........ r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line death to old CVS keyword ........ r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line fix some coding style ........ r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line platform we don't care about ........ r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines Issue #1754094: Improve the stack depth calculation in the compiler. There should be no other effect than a small decrease in memory use. Patch by Christopher Tur Lesniewski-Laas. ........ r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line pep8ify if blocks ........ r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line use floor division and add a test that exercises the tabsize codepath ........ r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line change test to what I intended ........ r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line some cleanups ........ r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line make inspect.isabstract() always return a boolean; add a test for it, too #7069 ........ r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line only clear a module's __dict__ if the module is the only one with a reference to it #7140 ........ r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE. ........ r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines Add a comment about unreachable code, and fix a typo ........ r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line use property api ........ r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line clarify buffer arg #7178 ........ r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line whitespace ........ r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line rewrite to be nice to other implementations ........ r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines rewrite for style, clarify, and comments Also, use the hasattr() like scheme of allowing BaseException exceptions through. ........ r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines Fix compilation error in debug mode. ........ r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line use 'is' instead of id() ........ r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line test expect base classes ........ r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line Use the correct function name in docstring. ........ r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line Remove mention of the old -X command line switch. ........ r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests. ........ r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line Use a single style for all the docstrings in the math module. ........ r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line I do not think the "railroad" program mentioned is still available. ........ r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line Fix constant name. ........ r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line prevent a rather unlikely segfault ........ r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line #7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs. ........ r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line spelling ........ r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line #7271: fix typo. ........ r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line discuss how to use -p ........ r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line Give the profile module a module directive. ........
16 years ago
36 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines Patch #1722225: Support QNX 6. ........ r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo. ........ r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines Fix issue2589: there was a potential integer overflow leading to memory corruption on esoteric platforms and incorrect behavior on normal platforms. ........ r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is passed in. (The assert won't prevent this in non-debug builds). ........ r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line Fix two typos. ........ r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines Fixed the semantic of timeout for socket.create_connection and all the upper level libraries that use it, including urllib2. Added and fixed some tests, and changed docs correspondingly. Thanks to John J Lee for the patch and the pusing, :) ........ r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines Fix typo in testSum ........ r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines * Mark intermedidate computes values (hi, lo, yr) as volatile. * Expand comments. * Swap variable names in the sum_exact code so that x and y are consistently chosen as the larger and smaller magnitude values respectively. ........ r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line Implement heapq in terms of less-than (to match list.sort()). ........ r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance. ........ r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines Fix issue 2782: be less strict about the format string type in strftime. Accept unicode and anything else ParseTuple "s#" can deal with. This matches the time.strftime behavior. ........ r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3. (I didn't regen configure, since I don't have a working autoconf.) ........ r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line Issue 3501: Make heapq support both __le__ and __lt__. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64365 | raymond.hettinger | 2008-06-17 19:56:57 -0500 (Tue, 17 Jun 2008) | 1 line Fix double decref. ........ r64370 | mark.dickinson | 2008-06-18 04:20:17 -0500 (Wed, 18 Jun 2008) | 2 lines Typo fix ........ r64406 | andrew.kuchling | 2008-06-19 09:02:30 -0500 (Thu, 19 Jun 2008) | 1 line Only include update_lines_cols() function when it's actually going to be used ........ r64408 | amaury.forgeotdarc | 2008-06-19 14:57:39 -0500 (Thu, 19 Jun 2008) | 2 lines test_macos can be skipped on non-mac platforms. ........ r64409 | andrew.kuchling | 2008-06-19 15:33:31 -0500 (Thu, 19 Jun 2008) | 1 line Put threading in front of thread ........ r64412 | amaury.forgeotdarc | 2008-06-19 16:17:12 -0500 (Thu, 19 Jun 2008) | 3 lines In test_site, correctly escape backslashes in path names. This allows the test to pass when the username begins with a lowercase 't'... ........ r64416 | vinay.sajip | 2008-06-19 17:40:17 -0500 (Thu, 19 Jun 2008) | 2 lines Bug #3136: fileConfig()'s disabling of old loggers is now conditional via an optional disable_existing_loggers parameter, but the default value is such that the old behaviour is preserved. Thanks to Leandro Lucarella for the patch. ........ r64417 | vinay.sajip | 2008-06-19 17:41:08 -0500 (Thu, 19 Jun 2008) | 1 line Updated with fix for #3136. ........ r64420 | andrew.kuchling | 2008-06-19 21:05:57 -0500 (Thu, 19 Jun 2008) | 1 line Various items ........ r64421 | andrew.kuchling | 2008-06-19 21:11:42 -0500 (Thu, 19 Jun 2008) | 1 line Fix comment typos ........ r64425 | andrew.kuchling | 2008-06-20 06:39:54 -0500 (Fri, 20 Jun 2008) | 1 line Various items ........ r64426 | mark.dickinson | 2008-06-20 09:53:43 -0500 (Fri, 20 Jun 2008) | 4 lines Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now returns (0, 0, 1) instead of (0, -1, 1), and slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9, 10, -1). ........ r64427 | mark.dickinson | 2008-06-20 10:17:41 -0500 (Fri, 20 Jun 2008) | 2 lines Fix outdated count of the number of new math module functions. ........ r64428 | mark.dickinson | 2008-06-20 10:26:19 -0500 (Fri, 20 Jun 2008) | 2 lines Fix another typo in math_sum comment ........
18 years ago
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines Patch #1722225: Support QNX 6. ........ r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo. ........ r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines Fix issue2589: there was a potential integer overflow leading to memory corruption on esoteric platforms and incorrect behavior on normal platforms. ........ r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is passed in. (The assert won't prevent this in non-debug builds). ........ r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line Fix two typos. ........ r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines Fixed the semantic of timeout for socket.create_connection and all the upper level libraries that use it, including urllib2. Added and fixed some tests, and changed docs correspondingly. Thanks to John J Lee for the patch and the pusing, :) ........ r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines Fix typo in testSum ........ r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines * Mark intermedidate computes values (hi, lo, yr) as volatile. * Expand comments. * Swap variable names in the sum_exact code so that x and y are consistently chosen as the larger and smaller magnitude values respectively. ........ r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line Implement heapq in terms of less-than (to match list.sort()). ........ r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance. ........ r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines Fix issue 2782: be less strict about the format string type in strftime. Accept unicode and anything else ParseTuple "s#" can deal with. This matches the time.strftime behavior. ........ r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3. (I didn't regen configure, since I don't have a working autoconf.) ........ r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line Issue 3501: Make heapq support both __le__ and __lt__. ........
18 years ago
Merged revisions 64365,64370,64406,64408-64409,64412,64416-64417,64420-64421,64425-64428 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64365 | raymond.hettinger | 2008-06-17 19:56:57 -0500 (Tue, 17 Jun 2008) | 1 line Fix double decref. ........ r64370 | mark.dickinson | 2008-06-18 04:20:17 -0500 (Wed, 18 Jun 2008) | 2 lines Typo fix ........ r64406 | andrew.kuchling | 2008-06-19 09:02:30 -0500 (Thu, 19 Jun 2008) | 1 line Only include update_lines_cols() function when it's actually going to be used ........ r64408 | amaury.forgeotdarc | 2008-06-19 14:57:39 -0500 (Thu, 19 Jun 2008) | 2 lines test_macos can be skipped on non-mac platforms. ........ r64409 | andrew.kuchling | 2008-06-19 15:33:31 -0500 (Thu, 19 Jun 2008) | 1 line Put threading in front of thread ........ r64412 | amaury.forgeotdarc | 2008-06-19 16:17:12 -0500 (Thu, 19 Jun 2008) | 3 lines In test_site, correctly escape backslashes in path names. This allows the test to pass when the username begins with a lowercase 't'... ........ r64416 | vinay.sajip | 2008-06-19 17:40:17 -0500 (Thu, 19 Jun 2008) | 2 lines Bug #3136: fileConfig()'s disabling of old loggers is now conditional via an optional disable_existing_loggers parameter, but the default value is such that the old behaviour is preserved. Thanks to Leandro Lucarella for the patch. ........ r64417 | vinay.sajip | 2008-06-19 17:41:08 -0500 (Thu, 19 Jun 2008) | 1 line Updated with fix for #3136. ........ r64420 | andrew.kuchling | 2008-06-19 21:05:57 -0500 (Thu, 19 Jun 2008) | 1 line Various items ........ r64421 | andrew.kuchling | 2008-06-19 21:11:42 -0500 (Thu, 19 Jun 2008) | 1 line Fix comment typos ........ r64425 | andrew.kuchling | 2008-06-20 06:39:54 -0500 (Fri, 20 Jun 2008) | 1 line Various items ........ r64426 | mark.dickinson | 2008-06-20 09:53:43 -0500 (Fri, 20 Jun 2008) | 4 lines Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now returns (0, 0, 1) instead of (0, -1, 1), and slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9, 10, -1). ........ r64427 | mark.dickinson | 2008-06-20 10:17:41 -0500 (Fri, 20 Jun 2008) | 2 lines Fix outdated count of the number of new math module functions. ........ r64428 | mark.dickinson | 2008-06-20 10:26:19 -0500 (Fri, 20 Jun 2008) | 2 lines Fix another typo in math_sum comment ........
18 years ago
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines Patch #1722225: Support QNX 6. ........ r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo. ........ r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines Fix issue2589: there was a potential integer overflow leading to memory corruption on esoteric platforms and incorrect behavior on normal platforms. ........ r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is passed in. (The assert won't prevent this in non-debug builds). ........ r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line Fix two typos. ........ r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines Fixed the semantic of timeout for socket.create_connection and all the upper level libraries that use it, including urllib2. Added and fixed some tests, and changed docs correspondingly. Thanks to John J Lee for the patch and the pusing, :) ........ r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines Fix typo in testSum ........ r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines * Mark intermedidate computes values (hi, lo, yr) as volatile. * Expand comments. * Swap variable names in the sum_exact code so that x and y are consistently chosen as the larger and smaller magnitude values respectively. ........ r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line Implement heapq in terms of less-than (to match list.sort()). ........ r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance. ........ r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines Fix issue 2782: be less strict about the format string type in strftime. Accept unicode and anything else ParseTuple "s#" can deal with. This matches the time.strftime behavior. ........ r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3. (I didn't regen configure, since I don't have a working autoconf.) ........ r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line Issue 3501: Make heapq support both __le__ and __lt__. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 65258,65292,65299,65308-65309,65315,65326 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r65258 | mark.dickinson | 2008-07-27 08:15:29 +0100 (Sun, 27 Jul 2008) | 4 lines Remove math.sum tests related to overflow, special values, and behaviour near the extremes of the floating-point range. (The behaviour of math.sum should be regarded as undefined in these cases.) ........ r65292 | mark.dickinson | 2008-07-29 19:45:38 +0100 (Tue, 29 Jul 2008) | 4 lines More modifications to tests for math.sum: replace the Python version of msum by a version using a different algorithm, and use the new float.fromhex method to specify test results exactly. ........ r65299 | mark.dickinson | 2008-07-30 13:01:41 +0100 (Wed, 30 Jul 2008) | 5 lines Fix special-value handling for math.sum. Also minor cleanups to the code: fix tabbing, remove trailing whitespace, and reformat to fit into 80 columns. ........ r65308 | mark.dickinson | 2008-07-30 17:20:10 +0100 (Wed, 30 Jul 2008) | 2 lines Rename math.sum to math.fsum ........ r65309 | mark.dickinson | 2008-07-30 17:25:16 +0100 (Wed, 30 Jul 2008) | 3 lines Replace math.sum with math.fsum in a couple of comments that were missed by r65308 ........ r65315 | mark.dickinson | 2008-07-30 21:23:15 +0100 (Wed, 30 Jul 2008) | 2 lines Add note about problems with math.fsum on x86 hardware. ........ r65326 | mark.dickinson | 2008-07-31 15:48:32 +0100 (Thu, 31 Jul 2008) | 2 lines Rename testSum to testFsum and move it to proper place in test_math.py ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 63542-63544,63546,63553,63563-63564,63567,63569,63576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63542 | mark.dickinson | 2008-05-22 20:35:30 -0500 (Thu, 22 May 2008) | 5 lines Issue #2819: Add math.sum, a function that sums a sequence of floats efficiently but with no intermediate loss of precision. Based on Raymond Hettinger's ASPN recipe. Thanks Jean Brouwers for the patch. ........ r63543 | mark.dickinson | 2008-05-22 21:36:48 -0500 (Thu, 22 May 2008) | 2 lines Add tests for math.sum (Issue #2819) ........ r63544 | mark.dickinson | 2008-05-22 22:30:01 -0500 (Thu, 22 May 2008) | 2 lines Better error reporting in test_math.py ........ r63546 | raymond.hettinger | 2008-05-22 23:32:43 -0500 (Thu, 22 May 2008) | 1 line Tweak the comments and formatting. ........ r63553 | mark.dickinson | 2008-05-23 07:07:36 -0500 (Fri, 23 May 2008) | 3 lines Skip math.sum tests on non IEEE 754 platforms, and on IEEE 754 platforms that exhibit the problem described in issue #2937. ........ r63563 | martin.v.loewis | 2008-05-23 10:18:28 -0500 (Fri, 23 May 2008) | 3 lines Issue #1390: Raise ValueError in toxml when an invalid comment would otherwise be produced. ........ r63564 | raymond.hettinger | 2008-05-23 12:21:44 -0500 (Fri, 23 May 2008) | 1 line Issue 2909: show how to name unpacked fields. ........ r63567 | raymond.hettinger | 2008-05-23 12:34:34 -0500 (Fri, 23 May 2008) | 1 line Fix typo ........ r63569 | martin.v.loewis | 2008-05-23 14:33:13 -0500 (Fri, 23 May 2008) | 3 lines Mention that the leaking of variables from list comprehensions is fixed in 3.0. ........ r63576 | martin.v.loewis | 2008-05-24 04:36:45 -0500 (Sat, 24 May 2008) | 3 lines Don't try to get the window size if it was never set before. Fixes the test failure on Solaris. ........
18 years ago
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
18 years ago
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
18 years ago
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
18 years ago
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
18 years ago
30 years ago
30 years ago
30 years ago
36 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
Merged revisions 59666-59679 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line Made vs9to8 Unix compatible ........ r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines Patch #1696. Don't attempt to close None in dry-run mode. ........ r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361, r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new documentation. The only significant difference is that round(x) returns a float to preserve backward-compatibility. See http://bugs.python.org/issue1689. ........ r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj ........ r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh: Regular Expression inline flags not handled correctly for some unicode characters. (Forward port from 2.5.2.) ........ r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line Added math.isinf() and math.isnan() ........ r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler ........ r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0 Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports ........ r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line Added copysign(x, y) function to the math module ........
18 years ago
30 years ago
36 years ago
36 years ago
36 years ago
  1. /* Math module -- standard C math library functions, pi and e */
  2. /* Here are some comments from Tim Peters, extracted from the
  3. discussion attached to http://bugs.python.org/issue1640. They
  4. describe the general aims of the math module with respect to
  5. special values, IEEE-754 floating-point exceptions, and Python
  6. exceptions.
  7. These are the "spirit of 754" rules:
  8. 1. If the mathematical result is a real number, but of magnitude too
  9. large to approximate by a machine float, overflow is signaled and the
  10. result is an infinity (with the appropriate sign).
  11. 2. If the mathematical result is a real number, but of magnitude too
  12. small to approximate by a machine float, underflow is signaled and the
  13. result is a zero (with the appropriate sign).
  14. 3. At a singularity (a value x such that the limit of f(y) as y
  15. approaches x exists and is an infinity), "divide by zero" is signaled
  16. and the result is an infinity (with the appropriate sign). This is
  17. complicated a little by that the left-side and right-side limits may
  18. not be the same; e.g., 1/x approaches +inf or -inf as x approaches 0
  19. from the positive or negative directions. In that specific case, the
  20. sign of the zero determines the result of 1/0.
  21. 4. At a point where a function has no defined result in the extended
  22. reals (i.e., the reals plus an infinity or two), invalid operation is
  23. signaled and a NaN is returned.
  24. And these are what Python has historically /tried/ to do (but not
  25. always successfully, as platform libm behavior varies a lot):
  26. For #1, raise OverflowError.
  27. For #2, return a zero (with the appropriate sign if that happens by
  28. accident ;-)).
  29. For #3 and #4, raise ValueError. It may have made sense to raise
  30. Python's ZeroDivisionError in #3, but historically that's only been
  31. raised for division by zero and mod by zero.
  32. */
  33. /*
  34. In general, on an IEEE-754 platform the aim is to follow the C99
  35. standard, including Annex 'F', whenever possible. Where the
  36. standard recommends raising the 'divide-by-zero' or 'invalid'
  37. floating-point exceptions, Python should raise a ValueError. Where
  38. the standard recommends raising 'overflow', Python should raise an
  39. OverflowError. In all other circumstances a value should be
  40. returned.
  41. */
  42. #include "Python.h"
  43. #include "_math.h"
  44. #include "clinic/mathmodule.c.h"
  45. /*[clinic input]
  46. module math
  47. [clinic start generated code]*/
  48. /*[clinic end generated code: output=da39a3ee5e6b4b0d input=76bc7002685dd942]*/
  49. /*
  50. sin(pi*x), giving accurate results for all finite x (especially x
  51. integral or close to an integer). This is here for use in the
  52. reflection formula for the gamma function. It conforms to IEEE
  53. 754-2008 for finite arguments, but not for infinities or nans.
  54. */
  55. static const double pi = 3.141592653589793238462643383279502884197;
  56. static const double logpi = 1.144729885849400174143427351353058711647;
  57. #if !defined(HAVE_ERF) || !defined(HAVE_ERFC)
  58. static const double sqrtpi = 1.772453850905516027298167483341145182798;
  59. #endif /* !defined(HAVE_ERF) || !defined(HAVE_ERFC) */
  60. /* Version of PyFloat_AsDouble() with in-line fast paths
  61. for exact floats and integers. Gives a substantial
  62. speed improvement for extracting float arguments.
  63. */
  64. #define ASSIGN_DOUBLE(target_var, obj, error_label) \
  65. if (PyFloat_CheckExact(obj)) { \
  66. target_var = PyFloat_AS_DOUBLE(obj); \
  67. } \
  68. else if (PyLong_CheckExact(obj)) { \
  69. target_var = PyLong_AsDouble(obj); \
  70. if (target_var == -1.0 && PyErr_Occurred()) { \
  71. goto error_label; \
  72. } \
  73. } \
  74. else { \
  75. target_var = PyFloat_AsDouble(obj); \
  76. if (target_var == -1.0 && PyErr_Occurred()) { \
  77. goto error_label; \
  78. } \
  79. }
  80. static double
  81. m_sinpi(double x)
  82. {
  83. double y, r;
  84. int n;
  85. /* this function should only ever be called for finite arguments */
  86. assert(Py_IS_FINITE(x));
  87. y = fmod(fabs(x), 2.0);
  88. n = (int)round(2.0*y);
  89. assert(0 <= n && n <= 4);
  90. switch (n) {
  91. case 0:
  92. r = sin(pi*y);
  93. break;
  94. case 1:
  95. r = cos(pi*(y-0.5));
  96. break;
  97. case 2:
  98. /* N.B. -sin(pi*(y-1.0)) is *not* equivalent: it would give
  99. -0.0 instead of 0.0 when y == 1.0. */
  100. r = sin(pi*(1.0-y));
  101. break;
  102. case 3:
  103. r = -cos(pi*(y-1.5));
  104. break;
  105. case 4:
  106. r = sin(pi*(y-2.0));
  107. break;
  108. default:
  109. Py_UNREACHABLE();
  110. }
  111. return copysign(1.0, x)*r;
  112. }
  113. /* Implementation of the real gamma function. In extensive but non-exhaustive
  114. random tests, this function proved accurate to within <= 10 ulps across the
  115. entire float domain. Note that accuracy may depend on the quality of the
  116. system math functions, the pow function in particular. Special cases
  117. follow C99 annex F. The parameters and method are tailored to platforms
  118. whose double format is the IEEE 754 binary64 format.
  119. Method: for x > 0.0 we use the Lanczos approximation with parameters N=13
  120. and g=6.024680040776729583740234375; these parameters are amongst those
  121. used by the Boost library. Following Boost (again), we re-express the
  122. Lanczos sum as a rational function, and compute it that way. The
  123. coefficients below were computed independently using MPFR, and have been
  124. double-checked against the coefficients in the Boost source code.
  125. For x < 0.0 we use the reflection formula.
  126. There's one minor tweak that deserves explanation: Lanczos' formula for
  127. Gamma(x) involves computing pow(x+g-0.5, x-0.5) / exp(x+g-0.5). For many x
  128. values, x+g-0.5 can be represented exactly. However, in cases where it
  129. can't be represented exactly the small error in x+g-0.5 can be magnified
  130. significantly by the pow and exp calls, especially for large x. A cheap
  131. correction is to multiply by (1 + e*g/(x+g-0.5)), where e is the error
  132. involved in the computation of x+g-0.5 (that is, e = computed value of
  133. x+g-0.5 - exact value of x+g-0.5). Here's the proof:
  134. Correction factor
  135. -----------------
  136. Write x+g-0.5 = y-e, where y is exactly representable as an IEEE 754
  137. double, and e is tiny. Then:
  138. pow(x+g-0.5,x-0.5)/exp(x+g-0.5) = pow(y-e, x-0.5)/exp(y-e)
  139. = pow(y, x-0.5)/exp(y) * C,
  140. where the correction_factor C is given by
  141. C = pow(1-e/y, x-0.5) * exp(e)
  142. Since e is tiny, pow(1-e/y, x-0.5) ~ 1-(x-0.5)*e/y, and exp(x) ~ 1+e, so:
  143. C ~ (1-(x-0.5)*e/y) * (1+e) ~ 1 + e*(y-(x-0.5))/y
  144. But y-(x-0.5) = g+e, and g+e ~ g. So we get C ~ 1 + e*g/y, and
  145. pow(x+g-0.5,x-0.5)/exp(x+g-0.5) ~ pow(y, x-0.5)/exp(y) * (1 + e*g/y),
  146. Note that for accuracy, when computing r*C it's better to do
  147. r + e*g/y*r;
  148. than
  149. r * (1 + e*g/y);
  150. since the addition in the latter throws away most of the bits of
  151. information in e*g/y.
  152. */
  153. #define LANCZOS_N 13
  154. static const double lanczos_g = 6.024680040776729583740234375;
  155. static const double lanczos_g_minus_half = 5.524680040776729583740234375;
  156. static const double lanczos_num_coeffs[LANCZOS_N] = {
  157. 23531376880.410759688572007674451636754734846804940,
  158. 42919803642.649098768957899047001988850926355848959,
  159. 35711959237.355668049440185451547166705960488635843,
  160. 17921034426.037209699919755754458931112671403265390,
  161. 6039542586.3520280050642916443072979210699388420708,
  162. 1439720407.3117216736632230727949123939715485786772,
  163. 248874557.86205415651146038641322942321632125127801,
  164. 31426415.585400194380614231628318205362874684987640,
  165. 2876370.6289353724412254090516208496135991145378768,
  166. 186056.26539522349504029498971604569928220784236328,
  167. 8071.6720023658162106380029022722506138218516325024,
  168. 210.82427775157934587250973392071336271166969580291,
  169. 2.5066282746310002701649081771338373386264310793408
  170. };
  171. /* denominator is x*(x+1)*...*(x+LANCZOS_N-2) */
  172. static const double lanczos_den_coeffs[LANCZOS_N] = {
  173. 0.0, 39916800.0, 120543840.0, 150917976.0, 105258076.0, 45995730.0,
  174. 13339535.0, 2637558.0, 357423.0, 32670.0, 1925.0, 66.0, 1.0};
  175. /* gamma values for small positive integers, 1 though NGAMMA_INTEGRAL */
  176. #define NGAMMA_INTEGRAL 23
  177. static const double gamma_integral[NGAMMA_INTEGRAL] = {
  178. 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0,
  179. 3628800.0, 39916800.0, 479001600.0, 6227020800.0, 87178291200.0,
  180. 1307674368000.0, 20922789888000.0, 355687428096000.0,
  181. 6402373705728000.0, 121645100408832000.0, 2432902008176640000.0,
  182. 51090942171709440000.0, 1124000727777607680000.0,
  183. };
  184. /* Lanczos' sum L_g(x), for positive x */
  185. static double
  186. lanczos_sum(double x)
  187. {
  188. double num = 0.0, den = 0.0;
  189. int i;
  190. assert(x > 0.0);
  191. /* evaluate the rational function lanczos_sum(x). For large
  192. x, the obvious algorithm risks overflow, so we instead
  193. rescale the denominator and numerator of the rational
  194. function by x**(1-LANCZOS_N) and treat this as a
  195. rational function in 1/x. This also reduces the error for
  196. larger x values. The choice of cutoff point (5.0 below) is
  197. somewhat arbitrary; in tests, smaller cutoff values than
  198. this resulted in lower accuracy. */
  199. if (x < 5.0) {
  200. for (i = LANCZOS_N; --i >= 0; ) {
  201. num = num * x + lanczos_num_coeffs[i];
  202. den = den * x + lanczos_den_coeffs[i];
  203. }
  204. }
  205. else {
  206. for (i = 0; i < LANCZOS_N; i++) {
  207. num = num / x + lanczos_num_coeffs[i];
  208. den = den / x + lanczos_den_coeffs[i];
  209. }
  210. }
  211. return num/den;
  212. }
  213. /* Constant for +infinity, generated in the same way as float('inf'). */
  214. static double
  215. m_inf(void)
  216. {
  217. #ifndef PY_NO_SHORT_FLOAT_REPR
  218. return _Py_dg_infinity(0);
  219. #else
  220. return Py_HUGE_VAL;
  221. #endif
  222. }
  223. /* Constant nan value, generated in the same way as float('nan'). */
  224. /* We don't currently assume that Py_NAN is defined everywhere. */
  225. #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
  226. static double
  227. m_nan(void)
  228. {
  229. #ifndef PY_NO_SHORT_FLOAT_REPR
  230. return _Py_dg_stdnan(0);
  231. #else
  232. return Py_NAN;
  233. #endif
  234. }
  235. #endif
  236. static double
  237. m_tgamma(double x)
  238. {
  239. double absx, r, y, z, sqrtpow;
  240. /* special cases */
  241. if (!Py_IS_FINITE(x)) {
  242. if (Py_IS_NAN(x) || x > 0.0)
  243. return x; /* tgamma(nan) = nan, tgamma(inf) = inf */
  244. else {
  245. errno = EDOM;
  246. return Py_NAN; /* tgamma(-inf) = nan, invalid */
  247. }
  248. }
  249. if (x == 0.0) {
  250. errno = EDOM;
  251. /* tgamma(+-0.0) = +-inf, divide-by-zero */
  252. return copysign(Py_HUGE_VAL, x);
  253. }
  254. /* integer arguments */
  255. if (x == floor(x)) {
  256. if (x < 0.0) {
  257. errno = EDOM; /* tgamma(n) = nan, invalid for */
  258. return Py_NAN; /* negative integers n */
  259. }
  260. if (x <= NGAMMA_INTEGRAL)
  261. return gamma_integral[(int)x - 1];
  262. }
  263. absx = fabs(x);
  264. /* tiny arguments: tgamma(x) ~ 1/x for x near 0 */
  265. if (absx < 1e-20) {
  266. r = 1.0/x;
  267. if (Py_IS_INFINITY(r))
  268. errno = ERANGE;
  269. return r;
  270. }
  271. /* large arguments: assuming IEEE 754 doubles, tgamma(x) overflows for
  272. x > 200, and underflows to +-0.0 for x < -200, not a negative
  273. integer. */
  274. if (absx > 200.0) {
  275. if (x < 0.0) {
  276. return 0.0/m_sinpi(x);
  277. }
  278. else {
  279. errno = ERANGE;
  280. return Py_HUGE_VAL;
  281. }
  282. }
  283. y = absx + lanczos_g_minus_half;
  284. /* compute error in sum */
  285. if (absx > lanczos_g_minus_half) {
  286. /* note: the correction can be foiled by an optimizing
  287. compiler that (incorrectly) thinks that an expression like
  288. a + b - a - b can be optimized to 0.0. This shouldn't
  289. happen in a standards-conforming compiler. */
  290. double q = y - absx;
  291. z = q - lanczos_g_minus_half;
  292. }
  293. else {
  294. double q = y - lanczos_g_minus_half;
  295. z = q - absx;
  296. }
  297. z = z * lanczos_g / y;
  298. if (x < 0.0) {
  299. r = -pi / m_sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
  300. r -= z * r;
  301. if (absx < 140.0) {
  302. r /= pow(y, absx - 0.5);
  303. }
  304. else {
  305. sqrtpow = pow(y, absx / 2.0 - 0.25);
  306. r /= sqrtpow;
  307. r /= sqrtpow;
  308. }
  309. }
  310. else {
  311. r = lanczos_sum(absx) / exp(y);
  312. r += z * r;
  313. if (absx < 140.0) {
  314. r *= pow(y, absx - 0.5);
  315. }
  316. else {
  317. sqrtpow = pow(y, absx / 2.0 - 0.25);
  318. r *= sqrtpow;
  319. r *= sqrtpow;
  320. }
  321. }
  322. if (Py_IS_INFINITY(r))
  323. errno = ERANGE;
  324. return r;
  325. }
  326. /*
  327. lgamma: natural log of the absolute value of the Gamma function.
  328. For large arguments, Lanczos' formula works extremely well here.
  329. */
  330. static double
  331. m_lgamma(double x)
  332. {
  333. double r;
  334. double absx;
  335. /* special cases */
  336. if (!Py_IS_FINITE(x)) {
  337. if (Py_IS_NAN(x))
  338. return x; /* lgamma(nan) = nan */
  339. else
  340. return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
  341. }
  342. /* integer arguments */
  343. if (x == floor(x) && x <= 2.0) {
  344. if (x <= 0.0) {
  345. errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
  346. return Py_HUGE_VAL; /* integers n <= 0 */
  347. }
  348. else {
  349. return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
  350. }
  351. }
  352. absx = fabs(x);
  353. /* tiny arguments: lgamma(x) ~ -log(fabs(x)) for small x */
  354. if (absx < 1e-20)
  355. return -log(absx);
  356. /* Lanczos' formula. We could save a fraction of a ulp in accuracy by
  357. having a second set of numerator coefficients for lanczos_sum that
  358. absorbed the exp(-lanczos_g) term, and throwing out the lanczos_g
  359. subtraction below; it's probably not worth it. */
  360. r = log(lanczos_sum(absx)) - lanczos_g;
  361. r += (absx - 0.5) * (log(absx + lanczos_g - 0.5) - 1);
  362. if (x < 0.0)
  363. /* Use reflection formula to get value for negative x. */
  364. r = logpi - log(fabs(m_sinpi(absx))) - log(absx) - r;
  365. if (Py_IS_INFINITY(r))
  366. errno = ERANGE;
  367. return r;
  368. }
  369. #if !defined(HAVE_ERF) || !defined(HAVE_ERFC)
  370. /*
  371. Implementations of the error function erf(x) and the complementary error
  372. function erfc(x).
  373. Method: we use a series approximation for erf for small x, and a continued
  374. fraction approximation for erfc(x) for larger x;
  375. combined with the relations erf(-x) = -erf(x) and erfc(x) = 1.0 - erf(x),
  376. this gives us erf(x) and erfc(x) for all x.
  377. The series expansion used is:
  378. erf(x) = x*exp(-x*x)/sqrt(pi) * [
  379. 2/1 + 4/3 x**2 + 8/15 x**4 + 16/105 x**6 + ...]
  380. The coefficient of x**(2k-2) here is 4**k*factorial(k)/factorial(2*k).
  381. This series converges well for smallish x, but slowly for larger x.
  382. The continued fraction expansion used is:
  383. erfc(x) = x*exp(-x*x)/sqrt(pi) * [1/(0.5 + x**2 -) 0.5/(2.5 + x**2 - )
  384. 3.0/(4.5 + x**2 - ) 7.5/(6.5 + x**2 - ) ...]
  385. after the first term, the general term has the form:
  386. k*(k-0.5)/(2*k+0.5 + x**2 - ...).
  387. This expansion converges fast for larger x, but convergence becomes
  388. infinitely slow as x approaches 0.0. The (somewhat naive) continued
  389. fraction evaluation algorithm used below also risks overflow for large x;
  390. but for large x, erfc(x) == 0.0 to within machine precision. (For
  391. example, erfc(30.0) is approximately 2.56e-393).
  392. Parameters: use series expansion for abs(x) < ERF_SERIES_CUTOFF and
  393. continued fraction expansion for ERF_SERIES_CUTOFF <= abs(x) <
  394. ERFC_CONTFRAC_CUTOFF. ERFC_SERIES_TERMS and ERFC_CONTFRAC_TERMS are the
  395. numbers of terms to use for the relevant expansions. */
  396. #define ERF_SERIES_CUTOFF 1.5
  397. #define ERF_SERIES_TERMS 25
  398. #define ERFC_CONTFRAC_CUTOFF 30.0
  399. #define ERFC_CONTFRAC_TERMS 50
  400. /*
  401. Error function, via power series.
  402. Given a finite float x, return an approximation to erf(x).
  403. Converges reasonably fast for small x.
  404. */
  405. static double
  406. m_erf_series(double x)
  407. {
  408. double x2, acc, fk, result;
  409. int i, saved_errno;
  410. x2 = x * x;
  411. acc = 0.0;
  412. fk = (double)ERF_SERIES_TERMS + 0.5;
  413. for (i = 0; i < ERF_SERIES_TERMS; i++) {
  414. acc = 2.0 + x2 * acc / fk;
  415. fk -= 1.0;
  416. }
  417. /* Make sure the exp call doesn't affect errno;
  418. see m_erfc_contfrac for more. */
  419. saved_errno = errno;
  420. result = acc * x * exp(-x2) / sqrtpi;
  421. errno = saved_errno;
  422. return result;
  423. }
  424. /*
  425. Complementary error function, via continued fraction expansion.
  426. Given a positive float x, return an approximation to erfc(x). Converges
  427. reasonably fast for x large (say, x > 2.0), and should be safe from
  428. overflow if x and nterms are not too large. On an IEEE 754 machine, with x
  429. <= 30.0, we're safe up to nterms = 100. For x >= 30.0, erfc(x) is smaller
  430. than the smallest representable nonzero float. */
  431. static double
  432. m_erfc_contfrac(double x)
  433. {
  434. double x2, a, da, p, p_last, q, q_last, b, result;
  435. int i, saved_errno;
  436. if (x >= ERFC_CONTFRAC_CUTOFF)
  437. return 0.0;
  438. x2 = x*x;
  439. a = 0.0;
  440. da = 0.5;
  441. p = 1.0; p_last = 0.0;
  442. q = da + x2; q_last = 1.0;
  443. for (i = 0; i < ERFC_CONTFRAC_TERMS; i++) {
  444. double temp;
  445. a += da;
  446. da += 2.0;
  447. b = da + x2;
  448. temp = p; p = b*p - a*p_last; p_last = temp;
  449. temp = q; q = b*q - a*q_last; q_last = temp;
  450. }
  451. /* Issue #8986: On some platforms, exp sets errno on underflow to zero;
  452. save the current errno value so that we can restore it later. */
  453. saved_errno = errno;
  454. result = p / q * x * exp(-x2) / sqrtpi;
  455. errno = saved_errno;
  456. return result;
  457. }
  458. #endif /* !defined(HAVE_ERF) || !defined(HAVE_ERFC) */
  459. /* Error function erf(x), for general x */
  460. static double
  461. m_erf(double x)
  462. {
  463. #ifdef HAVE_ERF
  464. return erf(x);
  465. #else
  466. double absx, cf;
  467. if (Py_IS_NAN(x))
  468. return x;
  469. absx = fabs(x);
  470. if (absx < ERF_SERIES_CUTOFF)
  471. return m_erf_series(x);
  472. else {
  473. cf = m_erfc_contfrac(absx);
  474. return x > 0.0 ? 1.0 - cf : cf - 1.0;
  475. }
  476. #endif
  477. }
  478. /* Complementary error function erfc(x), for general x. */
  479. static double
  480. m_erfc(double x)
  481. {
  482. #ifdef HAVE_ERFC
  483. return erfc(x);
  484. #else
  485. double absx, cf;
  486. if (Py_IS_NAN(x))
  487. return x;
  488. absx = fabs(x);
  489. if (absx < ERF_SERIES_CUTOFF)
  490. return 1.0 - m_erf_series(x);
  491. else {
  492. cf = m_erfc_contfrac(absx);
  493. return x > 0.0 ? cf : 2.0 - cf;
  494. }
  495. #endif
  496. }
  497. /*
  498. wrapper for atan2 that deals directly with special cases before
  499. delegating to the platform libm for the remaining cases. This
  500. is necessary to get consistent behaviour across platforms.
  501. Windows, FreeBSD and alpha Tru64 are amongst platforms that don't
  502. always follow C99.
  503. */
  504. static double
  505. m_atan2(double y, double x)
  506. {
  507. if (Py_IS_NAN(x) || Py_IS_NAN(y))
  508. return Py_NAN;
  509. if (Py_IS_INFINITY(y)) {
  510. if (Py_IS_INFINITY(x)) {
  511. if (copysign(1., x) == 1.)
  512. /* atan2(+-inf, +inf) == +-pi/4 */
  513. return copysign(0.25*Py_MATH_PI, y);
  514. else
  515. /* atan2(+-inf, -inf) == +-pi*3/4 */
  516. return copysign(0.75*Py_MATH_PI, y);
  517. }
  518. /* atan2(+-inf, x) == +-pi/2 for finite x */
  519. return copysign(0.5*Py_MATH_PI, y);
  520. }
  521. if (Py_IS_INFINITY(x) || y == 0.) {
  522. if (copysign(1., x) == 1.)
  523. /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
  524. return copysign(0., y);
  525. else
  526. /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
  527. return copysign(Py_MATH_PI, y);
  528. }
  529. return atan2(y, x);
  530. }
  531. /* IEEE 754-style remainder operation: x - n*y where n*y is the nearest
  532. multiple of y to x, taking n even in the case of a tie. Assuming an IEEE 754
  533. binary floating-point format, the result is always exact. */
  534. static double
  535. m_remainder(double x, double y)
  536. {
  537. /* Deal with most common case first. */
  538. if (Py_IS_FINITE(x) && Py_IS_FINITE(y)) {
  539. double absx, absy, c, m, r;
  540. if (y == 0.0) {
  541. return Py_NAN;
  542. }
  543. absx = fabs(x);
  544. absy = fabs(y);
  545. m = fmod(absx, absy);
  546. /*
  547. Warning: some subtlety here. What we *want* to know at this point is
  548. whether the remainder m is less than, equal to, or greater than half
  549. of absy. However, we can't do that comparison directly because we
  550. can't be sure that 0.5*absy is representable (the mutiplication
  551. might incur precision loss due to underflow). So instead we compare
  552. m with the complement c = absy - m: m < 0.5*absy if and only if m <
  553. c, and so on. The catch is that absy - m might also not be
  554. representable, but it turns out that it doesn't matter:
  555. - if m > 0.5*absy then absy - m is exactly representable, by
  556. Sterbenz's lemma, so m > c
  557. - if m == 0.5*absy then again absy - m is exactly representable
  558. and m == c
  559. - if m < 0.5*absy then either (i) 0.5*absy is exactly representable,
  560. in which case 0.5*absy < absy - m, so 0.5*absy <= c and hence m <
  561. c, or (ii) absy is tiny, either subnormal or in the lowest normal
  562. binade. Then absy - m is exactly representable and again m < c.
  563. */
  564. c = absy - m;
  565. if (m < c) {
  566. r = m;
  567. }
  568. else if (m > c) {
  569. r = -c;
  570. }
  571. else {
  572. /*
  573. Here absx is exactly halfway between two multiples of absy,
  574. and we need to choose the even multiple. x now has the form
  575. absx = n * absy + m
  576. for some integer n (recalling that m = 0.5*absy at this point).
  577. If n is even we want to return m; if n is odd, we need to
  578. return -m.
  579. So
  580. 0.5 * (absx - m) = (n/2) * absy
  581. and now reducing modulo absy gives us:
  582. | m, if n is odd
  583. fmod(0.5 * (absx - m), absy) = |
  584. | 0, if n is even
  585. Now m - 2.0 * fmod(...) gives the desired result: m
  586. if n is even, -m if m is odd.
  587. Note that all steps in fmod(0.5 * (absx - m), absy)
  588. will be computed exactly, with no rounding error
  589. introduced.
  590. */
  591. assert(m == c);
  592. r = m - 2.0 * fmod(0.5 * (absx - m), absy);
  593. }
  594. return copysign(1.0, x) * r;
  595. }
  596. /* Special values. */
  597. if (Py_IS_NAN(x)) {
  598. return x;
  599. }
  600. if (Py_IS_NAN(y)) {
  601. return y;
  602. }
  603. if (Py_IS_INFINITY(x)) {
  604. return Py_NAN;
  605. }
  606. assert(Py_IS_INFINITY(y));
  607. return x;
  608. }
  609. /*
  610. Various platforms (Solaris, OpenBSD) do nonstandard things for log(0),
  611. log(-ve), log(NaN). Here are wrappers for log and log10 that deal with
  612. special values directly, passing positive non-special values through to
  613. the system log/log10.
  614. */
  615. static double
  616. m_log(double x)
  617. {
  618. if (Py_IS_FINITE(x)) {
  619. if (x > 0.0)
  620. return log(x);
  621. errno = EDOM;
  622. if (x == 0.0)
  623. return -Py_HUGE_VAL; /* log(0) = -inf */
  624. else
  625. return Py_NAN; /* log(-ve) = nan */
  626. }
  627. else if (Py_IS_NAN(x))
  628. return x; /* log(nan) = nan */
  629. else if (x > 0.0)
  630. return x; /* log(inf) = inf */
  631. else {
  632. errno = EDOM;
  633. return Py_NAN; /* log(-inf) = nan */
  634. }
  635. }
  636. /*
  637. log2: log to base 2.
  638. Uses an algorithm that should:
  639. (a) produce exact results for powers of 2, and
  640. (b) give a monotonic log2 (for positive finite floats),
  641. assuming that the system log is monotonic.
  642. */
  643. static double
  644. m_log2(double x)
  645. {
  646. if (!Py_IS_FINITE(x)) {
  647. if (Py_IS_NAN(x))
  648. return x; /* log2(nan) = nan */
  649. else if (x > 0.0)
  650. return x; /* log2(+inf) = +inf */
  651. else {
  652. errno = EDOM;
  653. return Py_NAN; /* log2(-inf) = nan, invalid-operation */
  654. }
  655. }
  656. if (x > 0.0) {
  657. #ifdef HAVE_LOG2
  658. return log2(x);
  659. #else
  660. double m;
  661. int e;
  662. m = frexp(x, &e);
  663. /* We want log2(m * 2**e) == log(m) / log(2) + e. Care is needed when
  664. * x is just greater than 1.0: in that case e is 1, log(m) is negative,
  665. * and we get significant cancellation error from the addition of
  666. * log(m) / log(2) to e. The slight rewrite of the expression below
  667. * avoids this problem.
  668. */
  669. if (x >= 1.0) {
  670. return log(2.0 * m) / log(2.0) + (e - 1);
  671. }
  672. else {
  673. return log(m) / log(2.0) + e;
  674. }
  675. #endif
  676. }
  677. else if (x == 0.0) {
  678. errno = EDOM;
  679. return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
  680. }
  681. else {
  682. errno = EDOM;
  683. return Py_NAN; /* log2(-inf) = nan, invalid-operation */
  684. }
  685. }
  686. static double
  687. m_log10(double x)
  688. {
  689. if (Py_IS_FINITE(x)) {
  690. if (x > 0.0)
  691. return log10(x);
  692. errno = EDOM;
  693. if (x == 0.0)
  694. return -Py_HUGE_VAL; /* log10(0) = -inf */
  695. else
  696. return Py_NAN; /* log10(-ve) = nan */
  697. }
  698. else if (Py_IS_NAN(x))
  699. return x; /* log10(nan) = nan */
  700. else if (x > 0.0)
  701. return x; /* log10(inf) = inf */
  702. else {
  703. errno = EDOM;
  704. return Py_NAN; /* log10(-inf) = nan */
  705. }
  706. }
  707. /*[clinic input]
  708. math.gcd
  709. x as a: object
  710. y as b: object
  711. /
  712. greatest common divisor of x and y
  713. [clinic start generated code]*/
  714. static PyObject *
  715. math_gcd_impl(PyObject *module, PyObject *a, PyObject *b)
  716. /*[clinic end generated code: output=7b2e0c151bd7a5d8 input=c2691e57fb2a98fa]*/
  717. {
  718. PyObject *g;
  719. a = PyNumber_Index(a);
  720. if (a == NULL)
  721. return NULL;
  722. b = PyNumber_Index(b);
  723. if (b == NULL) {
  724. Py_DECREF(a);
  725. return NULL;
  726. }
  727. g = _PyLong_GCD(a, b);
  728. Py_DECREF(a);
  729. Py_DECREF(b);
  730. return g;
  731. }
  732. /* Call is_error when errno != 0, and where x is the result libm
  733. * returned. is_error will usually set up an exception and return
  734. * true (1), but may return false (0) without setting up an exception.
  735. */
  736. static int
  737. is_error(double x)
  738. {
  739. int result = 1; /* presumption of guilt */
  740. assert(errno); /* non-zero errno is a precondition for calling */
  741. if (errno == EDOM)
  742. PyErr_SetString(PyExc_ValueError, "math domain error");
  743. else if (errno == ERANGE) {
  744. /* ANSI C generally requires libm functions to set ERANGE
  745. * on overflow, but also generally *allows* them to set
  746. * ERANGE on underflow too. There's no consistency about
  747. * the latter across platforms.
  748. * Alas, C99 never requires that errno be set.
  749. * Here we suppress the underflow errors (libm functions
  750. * should return a zero on underflow, and +- HUGE_VAL on
  751. * overflow, so testing the result for zero suffices to
  752. * distinguish the cases).
  753. *
  754. * On some platforms (Ubuntu/ia64) it seems that errno can be
  755. * set to ERANGE for subnormal results that do *not* underflow
  756. * to zero. So to be safe, we'll ignore ERANGE whenever the
  757. * function result is less than one in absolute value.
  758. */
  759. if (fabs(x) < 1.0)
  760. result = 0;
  761. else
  762. PyErr_SetString(PyExc_OverflowError,
  763. "math range error");
  764. }
  765. else
  766. /* Unexpected math error */
  767. PyErr_SetFromErrno(PyExc_ValueError);
  768. return result;
  769. }
  770. /*
  771. math_1 is used to wrap a libm function f that takes a double
  772. argument and returns a double.
  773. The error reporting follows these rules, which are designed to do
  774. the right thing on C89/C99 platforms and IEEE 754/non IEEE 754
  775. platforms.
  776. - a NaN result from non-NaN inputs causes ValueError to be raised
  777. - an infinite result from finite inputs causes OverflowError to be
  778. raised if can_overflow is 1, or raises ValueError if can_overflow
  779. is 0.
  780. - if the result is finite and errno == EDOM then ValueError is
  781. raised
  782. - if the result is finite and nonzero and errno == ERANGE then
  783. OverflowError is raised
  784. The last rule is used to catch overflow on platforms which follow
  785. C89 but for which HUGE_VAL is not an infinity.
  786. For the majority of one-argument functions these rules are enough
  787. to ensure that Python's functions behave as specified in 'Annex F'
  788. of the C99 standard, with the 'invalid' and 'divide-by-zero'
  789. floating-point exceptions mapping to Python's ValueError and the
  790. 'overflow' floating-point exception mapping to OverflowError.
  791. math_1 only works for functions that don't have singularities *and*
  792. the possibility of overflow; fortunately, that covers everything we
  793. care about right now.
  794. */
  795. static PyObject *
  796. math_1_to_whatever(PyObject *arg, double (*func) (double),
  797. PyObject *(*from_double_func) (double),
  798. int can_overflow)
  799. {
  800. double x, r;
  801. x = PyFloat_AsDouble(arg);
  802. if (x == -1.0 && PyErr_Occurred())
  803. return NULL;
  804. errno = 0;
  805. PyFPE_START_PROTECT("in math_1", return 0);
  806. r = (*func)(x);
  807. PyFPE_END_PROTECT(r);
  808. if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
  809. PyErr_SetString(PyExc_ValueError,
  810. "math domain error"); /* invalid arg */
  811. return NULL;
  812. }
  813. if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
  814. if (can_overflow)
  815. PyErr_SetString(PyExc_OverflowError,
  816. "math range error"); /* overflow */
  817. else
  818. PyErr_SetString(PyExc_ValueError,
  819. "math domain error"); /* singularity */
  820. return NULL;
  821. }
  822. if (Py_IS_FINITE(r) && errno && is_error(r))
  823. /* this branch unnecessary on most platforms */
  824. return NULL;
  825. return (*from_double_func)(r);
  826. }
  827. /* variant of math_1, to be used when the function being wrapped is known to
  828. set errno properly (that is, errno = EDOM for invalid or divide-by-zero,
  829. errno = ERANGE for overflow). */
  830. static PyObject *
  831. math_1a(PyObject *arg, double (*func) (double))
  832. {
  833. double x, r;
  834. x = PyFloat_AsDouble(arg);
  835. if (x == -1.0 && PyErr_Occurred())
  836. return NULL;
  837. errno = 0;
  838. PyFPE_START_PROTECT("in math_1a", return 0);
  839. r = (*func)(x);
  840. PyFPE_END_PROTECT(r);
  841. if (errno && is_error(r))
  842. return NULL;
  843. return PyFloat_FromDouble(r);
  844. }
  845. /*
  846. math_2 is used to wrap a libm function f that takes two double
  847. arguments and returns a double.
  848. The error reporting follows these rules, which are designed to do
  849. the right thing on C89/C99 platforms and IEEE 754/non IEEE 754
  850. platforms.
  851. - a NaN result from non-NaN inputs causes ValueError to be raised
  852. - an infinite result from finite inputs causes OverflowError to be
  853. raised.
  854. - if the result is finite and errno == EDOM then ValueError is
  855. raised
  856. - if the result is finite and nonzero and errno == ERANGE then
  857. OverflowError is raised
  858. The last rule is used to catch overflow on platforms which follow
  859. C89 but for which HUGE_VAL is not an infinity.
  860. For most two-argument functions (copysign, fmod, hypot, atan2)
  861. these rules are enough to ensure that Python's functions behave as
  862. specified in 'Annex F' of the C99 standard, with the 'invalid' and
  863. 'divide-by-zero' floating-point exceptions mapping to Python's
  864. ValueError and the 'overflow' floating-point exception mapping to
  865. OverflowError.
  866. */
  867. static PyObject *
  868. math_1(PyObject *arg, double (*func) (double), int can_overflow)
  869. {
  870. return math_1_to_whatever(arg, func, PyFloat_FromDouble, can_overflow);
  871. }
  872. static PyObject *
  873. math_1_to_int(PyObject *arg, double (*func) (double), int can_overflow)
  874. {
  875. return math_1_to_whatever(arg, func, PyLong_FromDouble, can_overflow);
  876. }
  877. static PyObject *
  878. math_2(PyObject *const *args, Py_ssize_t nargs,
  879. double (*func) (double, double), const char *funcname)
  880. {
  881. double x, y, r;
  882. if (!_PyArg_CheckPositional(funcname, nargs, 2, 2))
  883. return NULL;
  884. x = PyFloat_AsDouble(args[0]);
  885. y = PyFloat_AsDouble(args[1]);
  886. if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
  887. return NULL;
  888. errno = 0;
  889. PyFPE_START_PROTECT("in math_2", return 0);
  890. r = (*func)(x, y);
  891. PyFPE_END_PROTECT(r);
  892. if (Py_IS_NAN(r)) {
  893. if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
  894. errno = EDOM;
  895. else
  896. errno = 0;
  897. }
  898. else if (Py_IS_INFINITY(r)) {
  899. if (Py_IS_FINITE(x) && Py_IS_FINITE(y))
  900. errno = ERANGE;
  901. else
  902. errno = 0;
  903. }
  904. if (errno && is_error(r))
  905. return NULL;
  906. else
  907. return PyFloat_FromDouble(r);
  908. }
  909. #define FUNC1(funcname, func, can_overflow, docstring) \
  910. static PyObject * math_##funcname(PyObject *self, PyObject *args) { \
  911. return math_1(args, func, can_overflow); \
  912. }\
  913. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  914. #define FUNC1A(funcname, func, docstring) \
  915. static PyObject * math_##funcname(PyObject *self, PyObject *args) { \
  916. return math_1a(args, func); \
  917. }\
  918. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  919. #define FUNC2(funcname, func, docstring) \
  920. static PyObject * math_##funcname(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { \
  921. return math_2(args, nargs, func, #funcname); \
  922. }\
  923. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  924. FUNC1(acos, acos, 0,
  925. "acos($module, x, /)\n--\n\n"
  926. "Return the arc cosine (measured in radians) of x.")
  927. FUNC1(acosh, m_acosh, 0,
  928. "acosh($module, x, /)\n--\n\n"
  929. "Return the inverse hyperbolic cosine of x.")
  930. FUNC1(asin, asin, 0,
  931. "asin($module, x, /)\n--\n\n"
  932. "Return the arc sine (measured in radians) of x.")
  933. FUNC1(asinh, m_asinh, 0,
  934. "asinh($module, x, /)\n--\n\n"
  935. "Return the inverse hyperbolic sine of x.")
  936. FUNC1(atan, atan, 0,
  937. "atan($module, x, /)\n--\n\n"
  938. "Return the arc tangent (measured in radians) of x.")
  939. FUNC2(atan2, m_atan2,
  940. "atan2($module, y, x, /)\n--\n\n"
  941. "Return the arc tangent (measured in radians) of y/x.\n\n"
  942. "Unlike atan(y/x), the signs of both x and y are considered.")
  943. FUNC1(atanh, m_atanh, 0,
  944. "atanh($module, x, /)\n--\n\n"
  945. "Return the inverse hyperbolic tangent of x.")
  946. /*[clinic input]
  947. math.ceil
  948. x as number: object
  949. /
  950. Return the ceiling of x as an Integral.
  951. This is the smallest integer >= x.
  952. [clinic start generated code]*/
  953. static PyObject *
  954. math_ceil(PyObject *module, PyObject *number)
  955. /*[clinic end generated code: output=6c3b8a78bc201c67 input=2725352806399cab]*/
  956. {
  957. _Py_IDENTIFIER(__ceil__);
  958. PyObject *method, *result;
  959. method = _PyObject_LookupSpecial(number, &PyId___ceil__);
  960. if (method == NULL) {
  961. if (PyErr_Occurred())
  962. return NULL;
  963. return math_1_to_int(number, ceil, 0);
  964. }
  965. result = _PyObject_CallNoArg(method);
  966. Py_DECREF(method);
  967. return result;
  968. }
  969. FUNC2(copysign, copysign,
  970. "copysign($module, x, y, /)\n--\n\n"
  971. "Return a float with the magnitude (absolute value) of x but the sign of y.\n\n"
  972. "On platforms that support signed zeros, copysign(1.0, -0.0)\n"
  973. "returns -1.0.\n")
  974. FUNC1(cos, cos, 0,
  975. "cos($module, x, /)\n--\n\n"
  976. "Return the cosine of x (measured in radians).")
  977. FUNC1(cosh, cosh, 1,
  978. "cosh($module, x, /)\n--\n\n"
  979. "Return the hyperbolic cosine of x.")
  980. FUNC1A(erf, m_erf,
  981. "erf($module, x, /)\n--\n\n"
  982. "Error function at x.")
  983. FUNC1A(erfc, m_erfc,
  984. "erfc($module, x, /)\n--\n\n"
  985. "Complementary error function at x.")
  986. FUNC1(exp, exp, 1,
  987. "exp($module, x, /)\n--\n\n"
  988. "Return e raised to the power of x.")
  989. FUNC1(expm1, m_expm1, 1,
  990. "expm1($module, x, /)\n--\n\n"
  991. "Return exp(x)-1.\n\n"
  992. "This function avoids the loss of precision involved in the direct "
  993. "evaluation of exp(x)-1 for small x.")
  994. FUNC1(fabs, fabs, 0,
  995. "fabs($module, x, /)\n--\n\n"
  996. "Return the absolute value of the float x.")
  997. /*[clinic input]
  998. math.floor
  999. x as number: object
  1000. /
  1001. Return the floor of x as an Integral.
  1002. This is the largest integer <= x.
  1003. [clinic start generated code]*/
  1004. static PyObject *
  1005. math_floor(PyObject *module, PyObject *number)
  1006. /*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/
  1007. {
  1008. _Py_IDENTIFIER(__floor__);
  1009. PyObject *method, *result;
  1010. method = _PyObject_LookupSpecial(number, &PyId___floor__);
  1011. if (method == NULL) {
  1012. if (PyErr_Occurred())
  1013. return NULL;
  1014. return math_1_to_int(number, floor, 0);
  1015. }
  1016. result = _PyObject_CallNoArg(method);
  1017. Py_DECREF(method);
  1018. return result;
  1019. }
  1020. FUNC1A(gamma, m_tgamma,
  1021. "gamma($module, x, /)\n--\n\n"
  1022. "Gamma function at x.")
  1023. FUNC1A(lgamma, m_lgamma,
  1024. "lgamma($module, x, /)\n--\n\n"
  1025. "Natural logarithm of absolute value of Gamma function at x.")
  1026. FUNC1(log1p, m_log1p, 0,
  1027. "log1p($module, x, /)\n--\n\n"
  1028. "Return the natural logarithm of 1+x (base e).\n\n"
  1029. "The result is computed in a way which is accurate for x near zero.")
  1030. FUNC2(remainder, m_remainder,
  1031. "remainder($module, x, y, /)\n--\n\n"
  1032. "Difference between x and the closest integer multiple of y.\n\n"
  1033. "Return x - n*y where n*y is the closest integer multiple of y.\n"
  1034. "In the case where x is exactly halfway between two multiples of\n"
  1035. "y, the nearest even value of n is used. The result is always exact.")
  1036. FUNC1(sin, sin, 0,
  1037. "sin($module, x, /)\n--\n\n"
  1038. "Return the sine of x (measured in radians).")
  1039. FUNC1(sinh, sinh, 1,
  1040. "sinh($module, x, /)\n--\n\n"
  1041. "Return the hyperbolic sine of x.")
  1042. FUNC1(sqrt, sqrt, 0,
  1043. "sqrt($module, x, /)\n--\n\n"
  1044. "Return the square root of x.")
  1045. FUNC1(tan, tan, 0,
  1046. "tan($module, x, /)\n--\n\n"
  1047. "Return the tangent of x (measured in radians).")
  1048. FUNC1(tanh, tanh, 0,
  1049. "tanh($module, x, /)\n--\n\n"
  1050. "Return the hyperbolic tangent of x.")
  1051. /* Precision summation function as msum() by Raymond Hettinger in
  1052. <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090>,
  1053. enhanced with the exact partials sum and roundoff from Mark
  1054. Dickinson's post at <http://bugs.python.org/file10357/msum4.py>.
  1055. See those links for more details, proofs and other references.
  1056. Note 1: IEEE 754R floating point semantics are assumed,
  1057. but the current implementation does not re-establish special
  1058. value semantics across iterations (i.e. handling -Inf + Inf).
  1059. Note 2: No provision is made for intermediate overflow handling;
  1060. therefore, sum([1e+308, 1e-308, 1e+308]) returns 1e+308 while
  1061. sum([1e+308, 1e+308, 1e-308]) raises an OverflowError due to the
  1062. overflow of the first partial sum.
  1063. Note 3: The intermediate values lo, yr, and hi are declared volatile so
  1064. aggressive compilers won't algebraically reduce lo to always be exactly 0.0.
  1065. Also, the volatile declaration forces the values to be stored in memory as
  1066. regular doubles instead of extended long precision (80-bit) values. This
  1067. prevents double rounding because any addition or subtraction of two doubles
  1068. can be resolved exactly into double-sized hi and lo values. As long as the
  1069. hi value gets forced into a double before yr and lo are computed, the extra
  1070. bits in downstream extended precision operations (x87 for example) will be
  1071. exactly zero and therefore can be losslessly stored back into a double,
  1072. thereby preventing double rounding.
  1073. Note 4: A similar implementation is in Modules/cmathmodule.c.
  1074. Be sure to update both when making changes.
  1075. Note 5: The signature of math.fsum() differs from builtins.sum()
  1076. because the start argument doesn't make sense in the context of
  1077. accurate summation. Since the partials table is collapsed before
  1078. returning a result, sum(seq2, start=sum(seq1)) may not equal the
  1079. accurate result returned by sum(itertools.chain(seq1, seq2)).
  1080. */
  1081. #define NUM_PARTIALS 32 /* initial partials array size, on stack */
  1082. /* Extend the partials array p[] by doubling its size. */
  1083. static int /* non-zero on error */
  1084. _fsum_realloc(double **p_ptr, Py_ssize_t n,
  1085. double *ps, Py_ssize_t *m_ptr)
  1086. {
  1087. void *v = NULL;
  1088. Py_ssize_t m = *m_ptr;
  1089. m += m; /* double */
  1090. if (n < m && (size_t)m < ((size_t)PY_SSIZE_T_MAX / sizeof(double))) {
  1091. double *p = *p_ptr;
  1092. if (p == ps) {
  1093. v = PyMem_Malloc(sizeof(double) * m);
  1094. if (v != NULL)
  1095. memcpy(v, ps, sizeof(double) * n);
  1096. }
  1097. else
  1098. v = PyMem_Realloc(p, sizeof(double) * m);
  1099. }
  1100. if (v == NULL) { /* size overflow or no memory */
  1101. PyErr_SetString(PyExc_MemoryError, "math.fsum partials");
  1102. return 1;
  1103. }
  1104. *p_ptr = (double*) v;
  1105. *m_ptr = m;
  1106. return 0;
  1107. }
  1108. /* Full precision summation of a sequence of floats.
  1109. def msum(iterable):
  1110. partials = [] # sorted, non-overlapping partial sums
  1111. for x in iterable:
  1112. i = 0
  1113. for y in partials:
  1114. if abs(x) < abs(y):
  1115. x, y = y, x
  1116. hi = x + y
  1117. lo = y - (hi - x)
  1118. if lo:
  1119. partials[i] = lo
  1120. i += 1
  1121. x = hi
  1122. partials[i:] = [x]
  1123. return sum_exact(partials)
  1124. Rounded x+y stored in hi with the roundoff stored in lo. Together hi+lo
  1125. are exactly equal to x+y. The inner loop applies hi/lo summation to each
  1126. partial so that the list of partial sums remains exact.
  1127. Sum_exact() adds the partial sums exactly and correctly rounds the final
  1128. result (using the round-half-to-even rule). The items in partials remain
  1129. non-zero, non-special, non-overlapping and strictly increasing in
  1130. magnitude, but possibly not all having the same sign.
  1131. Depends on IEEE 754 arithmetic guarantees and half-even rounding.
  1132. */
  1133. /*[clinic input]
  1134. math.fsum
  1135. seq: object
  1136. /
  1137. Return an accurate floating point sum of values in the iterable seq.
  1138. Assumes IEEE-754 floating point arithmetic.
  1139. [clinic start generated code]*/
  1140. static PyObject *
  1141. math_fsum(PyObject *module, PyObject *seq)
  1142. /*[clinic end generated code: output=ba5c672b87fe34fc input=c51b7d8caf6f6e82]*/
  1143. {
  1144. PyObject *item, *iter, *sum = NULL;
  1145. Py_ssize_t i, j, n = 0, m = NUM_PARTIALS;
  1146. double x, y, t, ps[NUM_PARTIALS], *p = ps;
  1147. double xsave, special_sum = 0.0, inf_sum = 0.0;
  1148. volatile double hi, yr, lo;
  1149. iter = PyObject_GetIter(seq);
  1150. if (iter == NULL)
  1151. return NULL;
  1152. PyFPE_START_PROTECT("fsum", Py_DECREF(iter); return NULL)
  1153. for(;;) { /* for x in iterable */
  1154. assert(0 <= n && n <= m);
  1155. assert((m == NUM_PARTIALS && p == ps) ||
  1156. (m > NUM_PARTIALS && p != NULL));
  1157. item = PyIter_Next(iter);
  1158. if (item == NULL) {
  1159. if (PyErr_Occurred())
  1160. goto _fsum_error;
  1161. break;
  1162. }
  1163. ASSIGN_DOUBLE(x, item, error_with_item);
  1164. Py_DECREF(item);
  1165. xsave = x;
  1166. for (i = j = 0; j < n; j++) { /* for y in partials */
  1167. y = p[j];
  1168. if (fabs(x) < fabs(y)) {
  1169. t = x; x = y; y = t;
  1170. }
  1171. hi = x + y;
  1172. yr = hi - x;
  1173. lo = y - yr;
  1174. if (lo != 0.0)
  1175. p[i++] = lo;
  1176. x = hi;
  1177. }
  1178. n = i; /* ps[i:] = [x] */
  1179. if (x != 0.0) {
  1180. if (! Py_IS_FINITE(x)) {
  1181. /* a nonfinite x could arise either as
  1182. a result of intermediate overflow, or
  1183. as a result of a nan or inf in the
  1184. summands */
  1185. if (Py_IS_FINITE(xsave)) {
  1186. PyErr_SetString(PyExc_OverflowError,
  1187. "intermediate overflow in fsum");
  1188. goto _fsum_error;
  1189. }
  1190. if (Py_IS_INFINITY(xsave))
  1191. inf_sum += xsave;
  1192. special_sum += xsave;
  1193. /* reset partials */
  1194. n = 0;
  1195. }
  1196. else if (n >= m && _fsum_realloc(&p, n, ps, &m))
  1197. goto _fsum_error;
  1198. else
  1199. p[n++] = x;
  1200. }
  1201. }
  1202. if (special_sum != 0.0) {
  1203. if (Py_IS_NAN(inf_sum))
  1204. PyErr_SetString(PyExc_ValueError,
  1205. "-inf + inf in fsum");
  1206. else
  1207. sum = PyFloat_FromDouble(special_sum);
  1208. goto _fsum_error;
  1209. }
  1210. hi = 0.0;
  1211. if (n > 0) {
  1212. hi = p[--n];
  1213. /* sum_exact(ps, hi) from the top, stop when the sum becomes
  1214. inexact. */
  1215. while (n > 0) {
  1216. x = hi;
  1217. y = p[--n];
  1218. assert(fabs(y) < fabs(x));
  1219. hi = x + y;
  1220. yr = hi - x;
  1221. lo = y - yr;
  1222. if (lo != 0.0)
  1223. break;
  1224. }
  1225. /* Make half-even rounding work across multiple partials.
  1226. Needed so that sum([1e-16, 1, 1e16]) will round-up the last
  1227. digit to two instead of down to zero (the 1e-16 makes the 1
  1228. slightly closer to two). With a potential 1 ULP rounding
  1229. error fixed-up, math.fsum() can guarantee commutativity. */
  1230. if (n > 0 && ((lo < 0.0 && p[n-1] < 0.0) ||
  1231. (lo > 0.0 && p[n-1] > 0.0))) {
  1232. y = lo * 2.0;
  1233. x = hi + y;
  1234. yr = x - hi;
  1235. if (y == yr)
  1236. hi = x;
  1237. }
  1238. }
  1239. sum = PyFloat_FromDouble(hi);
  1240. _fsum_error:
  1241. PyFPE_END_PROTECT(hi)
  1242. Py_DECREF(iter);
  1243. if (p != ps)
  1244. PyMem_Free(p);
  1245. return sum;
  1246. error_with_item:
  1247. Py_DECREF(item);
  1248. goto _fsum_error;
  1249. }
  1250. #undef NUM_PARTIALS
  1251. /* Return the smallest integer k such that n < 2**k, or 0 if n == 0.
  1252. * Equivalent to floor(lg(x))+1. Also equivalent to: bitwidth_of_type -
  1253. * count_leading_zero_bits(x)
  1254. */
  1255. /* XXX: This routine does more or less the same thing as
  1256. * bits_in_digit() in Objects/longobject.c. Someday it would be nice to
  1257. * consolidate them. On BSD, there's a library function called fls()
  1258. * that we could use, and GCC provides __builtin_clz().
  1259. */
  1260. static unsigned long
  1261. bit_length(unsigned long n)
  1262. {
  1263. unsigned long len = 0;
  1264. while (n != 0) {
  1265. ++len;
  1266. n >>= 1;
  1267. }
  1268. return len;
  1269. }
  1270. static unsigned long
  1271. count_set_bits(unsigned long n)
  1272. {
  1273. unsigned long count = 0;
  1274. while (n != 0) {
  1275. ++count;
  1276. n &= n - 1; /* clear least significant bit */
  1277. }
  1278. return count;
  1279. }
  1280. /* Divide-and-conquer factorial algorithm
  1281. *
  1282. * Based on the formula and pseudo-code provided at:
  1283. * http://www.luschny.de/math/factorial/binarysplitfact.html
  1284. *
  1285. * Faster algorithms exist, but they're more complicated and depend on
  1286. * a fast prime factorization algorithm.
  1287. *
  1288. * Notes on the algorithm
  1289. * ----------------------
  1290. *
  1291. * factorial(n) is written in the form 2**k * m, with m odd. k and m are
  1292. * computed separately, and then combined using a left shift.
  1293. *
  1294. * The function factorial_odd_part computes the odd part m (i.e., the greatest
  1295. * odd divisor) of factorial(n), using the formula:
  1296. *
  1297. * factorial_odd_part(n) =
  1298. *
  1299. * product_{i >= 0} product_{0 < j <= n / 2**i, j odd} j
  1300. *
  1301. * Example: factorial_odd_part(20) =
  1302. *
  1303. * (1) *
  1304. * (1) *
  1305. * (1 * 3 * 5) *
  1306. * (1 * 3 * 5 * 7 * 9)
  1307. * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
  1308. *
  1309. * Here i goes from large to small: the first term corresponds to i=4 (any
  1310. * larger i gives an empty product), and the last term corresponds to i=0.
  1311. * Each term can be computed from the last by multiplying by the extra odd
  1312. * numbers required: e.g., to get from the penultimate term to the last one,
  1313. * we multiply by (11 * 13 * 15 * 17 * 19).
  1314. *
  1315. * To see a hint of why this formula works, here are the same numbers as above
  1316. * but with the even parts (i.e., the appropriate powers of 2) included. For
  1317. * each subterm in the product for i, we multiply that subterm by 2**i:
  1318. *
  1319. * factorial(20) =
  1320. *
  1321. * (16) *
  1322. * (8) *
  1323. * (4 * 12 * 20) *
  1324. * (2 * 6 * 10 * 14 * 18) *
  1325. * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
  1326. *
  1327. * The factorial_partial_product function computes the product of all odd j in
  1328. * range(start, stop) for given start and stop. It's used to compute the
  1329. * partial products like (11 * 13 * 15 * 17 * 19) in the example above. It
  1330. * operates recursively, repeatedly splitting the range into two roughly equal
  1331. * pieces until the subranges are small enough to be computed using only C
  1332. * integer arithmetic.
  1333. *
  1334. * The two-valuation k (i.e., the exponent of the largest power of 2 dividing
  1335. * the factorial) is computed independently in the main math_factorial
  1336. * function. By standard results, its value is:
  1337. *
  1338. * two_valuation = n//2 + n//4 + n//8 + ....
  1339. *
  1340. * It can be shown (e.g., by complete induction on n) that two_valuation is
  1341. * equal to n - count_set_bits(n), where count_set_bits(n) gives the number of
  1342. * '1'-bits in the binary expansion of n.
  1343. */
  1344. /* factorial_partial_product: Compute product(range(start, stop, 2)) using
  1345. * divide and conquer. Assumes start and stop are odd and stop > start.
  1346. * max_bits must be >= bit_length(stop - 2). */
  1347. static PyObject *
  1348. factorial_partial_product(unsigned long start, unsigned long stop,
  1349. unsigned long max_bits)
  1350. {
  1351. unsigned long midpoint, num_operands;
  1352. PyObject *left = NULL, *right = NULL, *result = NULL;
  1353. /* If the return value will fit an unsigned long, then we can
  1354. * multiply in a tight, fast loop where each multiply is O(1).
  1355. * Compute an upper bound on the number of bits required to store
  1356. * the answer.
  1357. *
  1358. * Storing some integer z requires floor(lg(z))+1 bits, which is
  1359. * conveniently the value returned by bit_length(z). The
  1360. * product x*y will require at most
  1361. * bit_length(x) + bit_length(y) bits to store, based
  1362. * on the idea that lg product = lg x + lg y.
  1363. *
  1364. * We know that stop - 2 is the largest number to be multiplied. From
  1365. * there, we have: bit_length(answer) <= num_operands *
  1366. * bit_length(stop - 2)
  1367. */
  1368. num_operands = (stop - start) / 2;
  1369. /* The "num_operands <= 8 * SIZEOF_LONG" check guards against the
  1370. * unlikely case of an overflow in num_operands * max_bits. */
  1371. if (num_operands <= 8 * SIZEOF_LONG &&
  1372. num_operands * max_bits <= 8 * SIZEOF_LONG) {
  1373. unsigned long j, total;
  1374. for (total = start, j = start + 2; j < stop; j += 2)
  1375. total *= j;
  1376. return PyLong_FromUnsignedLong(total);
  1377. }
  1378. /* find midpoint of range(start, stop), rounded up to next odd number. */
  1379. midpoint = (start + num_operands) | 1;
  1380. left = factorial_partial_product(start, midpoint,
  1381. bit_length(midpoint - 2));
  1382. if (left == NULL)
  1383. goto error;
  1384. right = factorial_partial_product(midpoint, stop, max_bits);
  1385. if (right == NULL)
  1386. goto error;
  1387. result = PyNumber_Multiply(left, right);
  1388. error:
  1389. Py_XDECREF(left);
  1390. Py_XDECREF(right);
  1391. return result;
  1392. }
  1393. /* factorial_odd_part: compute the odd part of factorial(n). */
  1394. static PyObject *
  1395. factorial_odd_part(unsigned long n)
  1396. {
  1397. long i;
  1398. unsigned long v, lower, upper;
  1399. PyObject *partial, *tmp, *inner, *outer;
  1400. inner = PyLong_FromLong(1);
  1401. if (inner == NULL)
  1402. return NULL;
  1403. outer = inner;
  1404. Py_INCREF(outer);
  1405. upper = 3;
  1406. for (i = bit_length(n) - 2; i >= 0; i--) {
  1407. v = n >> i;
  1408. if (v <= 2)
  1409. continue;
  1410. lower = upper;
  1411. /* (v + 1) | 1 = least odd integer strictly larger than n / 2**i */
  1412. upper = (v + 1) | 1;
  1413. /* Here inner is the product of all odd integers j in the range (0,
  1414. n/2**(i+1)]. The factorial_partial_product call below gives the
  1415. product of all odd integers j in the range (n/2**(i+1), n/2**i]. */
  1416. partial = factorial_partial_product(lower, upper, bit_length(upper-2));
  1417. /* inner *= partial */
  1418. if (partial == NULL)
  1419. goto error;
  1420. tmp = PyNumber_Multiply(inner, partial);
  1421. Py_DECREF(partial);
  1422. if (tmp == NULL)
  1423. goto error;
  1424. Py_DECREF(inner);
  1425. inner = tmp;
  1426. /* Now inner is the product of all odd integers j in the range (0,
  1427. n/2**i], giving the inner product in the formula above. */
  1428. /* outer *= inner; */
  1429. tmp = PyNumber_Multiply(outer, inner);
  1430. if (tmp == NULL)
  1431. goto error;
  1432. Py_DECREF(outer);
  1433. outer = tmp;
  1434. }
  1435. Py_DECREF(inner);
  1436. return outer;
  1437. error:
  1438. Py_DECREF(outer);
  1439. Py_DECREF(inner);
  1440. return NULL;
  1441. }
  1442. /* Lookup table for small factorial values */
  1443. static const unsigned long SmallFactorials[] = {
  1444. 1, 1, 2, 6, 24, 120, 720, 5040, 40320,
  1445. 362880, 3628800, 39916800, 479001600,
  1446. #if SIZEOF_LONG >= 8
  1447. 6227020800, 87178291200, 1307674368000,
  1448. 20922789888000, 355687428096000, 6402373705728000,
  1449. 121645100408832000, 2432902008176640000
  1450. #endif
  1451. };
  1452. /*[clinic input]
  1453. math.factorial
  1454. x as arg: object
  1455. /
  1456. Find x!.
  1457. Raise a ValueError if x is negative or non-integral.
  1458. [clinic start generated code]*/
  1459. static PyObject *
  1460. math_factorial(PyObject *module, PyObject *arg)
  1461. /*[clinic end generated code: output=6686f26fae00e9ca input=6d1c8105c0d91fb4]*/
  1462. {
  1463. long x;
  1464. int overflow;
  1465. PyObject *result, *odd_part, *two_valuation, *pyint_form;
  1466. if (PyFloat_Check(arg)) {
  1467. PyObject *lx;
  1468. double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
  1469. if (!(Py_IS_FINITE(dx) && dx == floor(dx))) {
  1470. PyErr_SetString(PyExc_ValueError,
  1471. "factorial() only accepts integral values");
  1472. return NULL;
  1473. }
  1474. lx = PyLong_FromDouble(dx);
  1475. if (lx == NULL)
  1476. return NULL;
  1477. x = PyLong_AsLongAndOverflow(lx, &overflow);
  1478. Py_DECREF(lx);
  1479. }
  1480. else {
  1481. pyint_form = PyNumber_Index(arg);
  1482. if (pyint_form == NULL) {
  1483. return NULL;
  1484. }
  1485. x = PyLong_AsLongAndOverflow(pyint_form, &overflow);
  1486. Py_DECREF(pyint_form);
  1487. }
  1488. if (x == -1 && PyErr_Occurred()) {
  1489. return NULL;
  1490. }
  1491. else if (overflow == 1) {
  1492. PyErr_Format(PyExc_OverflowError,
  1493. "factorial() argument should not exceed %ld",
  1494. LONG_MAX);
  1495. return NULL;
  1496. }
  1497. else if (overflow == -1 || x < 0) {
  1498. PyErr_SetString(PyExc_ValueError,
  1499. "factorial() not defined for negative values");
  1500. return NULL;
  1501. }
  1502. /* use lookup table if x is small */
  1503. if (x < (long)Py_ARRAY_LENGTH(SmallFactorials))
  1504. return PyLong_FromUnsignedLong(SmallFactorials[x]);
  1505. /* else express in the form odd_part * 2**two_valuation, and compute as
  1506. odd_part << two_valuation. */
  1507. odd_part = factorial_odd_part(x);
  1508. if (odd_part == NULL)
  1509. return NULL;
  1510. two_valuation = PyLong_FromLong(x - count_set_bits(x));
  1511. if (two_valuation == NULL) {
  1512. Py_DECREF(odd_part);
  1513. return NULL;
  1514. }
  1515. result = PyNumber_Lshift(odd_part, two_valuation);
  1516. Py_DECREF(two_valuation);
  1517. Py_DECREF(odd_part);
  1518. return result;
  1519. }
  1520. /*[clinic input]
  1521. math.trunc
  1522. x: object
  1523. /
  1524. Truncates the Real x to the nearest Integral toward 0.
  1525. Uses the __trunc__ magic method.
  1526. [clinic start generated code]*/
  1527. static PyObject *
  1528. math_trunc(PyObject *module, PyObject *x)
  1529. /*[clinic end generated code: output=34b9697b707e1031 input=2168b34e0a09134d]*/
  1530. {
  1531. _Py_IDENTIFIER(__trunc__);
  1532. PyObject *trunc, *result;
  1533. if (Py_TYPE(x)->tp_dict == NULL) {
  1534. if (PyType_Ready(Py_TYPE(x)) < 0)
  1535. return NULL;
  1536. }
  1537. trunc = _PyObject_LookupSpecial(x, &PyId___trunc__);
  1538. if (trunc == NULL) {
  1539. if (!PyErr_Occurred())
  1540. PyErr_Format(PyExc_TypeError,
  1541. "type %.100s doesn't define __trunc__ method",
  1542. Py_TYPE(x)->tp_name);
  1543. return NULL;
  1544. }
  1545. result = _PyObject_CallNoArg(trunc);
  1546. Py_DECREF(trunc);
  1547. return result;
  1548. }
  1549. /*[clinic input]
  1550. math.frexp
  1551. x: double
  1552. /
  1553. Return the mantissa and exponent of x, as pair (m, e).
  1554. m is a float and e is an int, such that x = m * 2.**e.
  1555. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
  1556. [clinic start generated code]*/
  1557. static PyObject *
  1558. math_frexp_impl(PyObject *module, double x)
  1559. /*[clinic end generated code: output=03e30d252a15ad4a input=96251c9e208bc6e9]*/
  1560. {
  1561. int i;
  1562. /* deal with special cases directly, to sidestep platform
  1563. differences */
  1564. if (Py_IS_NAN(x) || Py_IS_INFINITY(x) || !x) {
  1565. i = 0;
  1566. }
  1567. else {
  1568. PyFPE_START_PROTECT("in math_frexp", return 0);
  1569. x = frexp(x, &i);
  1570. PyFPE_END_PROTECT(x);
  1571. }
  1572. return Py_BuildValue("(di)", x, i);
  1573. }
  1574. /*[clinic input]
  1575. math.ldexp
  1576. x: double
  1577. i: object
  1578. /
  1579. Return x * (2**i).
  1580. This is essentially the inverse of frexp().
  1581. [clinic start generated code]*/
  1582. static PyObject *
  1583. math_ldexp_impl(PyObject *module, double x, PyObject *i)
  1584. /*[clinic end generated code: output=b6892f3c2df9cc6a input=17d5970c1a40a8c1]*/
  1585. {
  1586. double r;
  1587. long exp;
  1588. int overflow;
  1589. if (PyLong_Check(i)) {
  1590. /* on overflow, replace exponent with either LONG_MAX
  1591. or LONG_MIN, depending on the sign. */
  1592. exp = PyLong_AsLongAndOverflow(i, &overflow);
  1593. if (exp == -1 && PyErr_Occurred())
  1594. return NULL;
  1595. if (overflow)
  1596. exp = overflow < 0 ? LONG_MIN : LONG_MAX;
  1597. }
  1598. else {
  1599. PyErr_SetString(PyExc_TypeError,
  1600. "Expected an int as second argument to ldexp.");
  1601. return NULL;
  1602. }
  1603. if (x == 0. || !Py_IS_FINITE(x)) {
  1604. /* NaNs, zeros and infinities are returned unchanged */
  1605. r = x;
  1606. errno = 0;
  1607. } else if (exp > INT_MAX) {
  1608. /* overflow */
  1609. r = copysign(Py_HUGE_VAL, x);
  1610. errno = ERANGE;
  1611. } else if (exp < INT_MIN) {
  1612. /* underflow to +-0 */
  1613. r = copysign(0., x);
  1614. errno = 0;
  1615. } else {
  1616. errno = 0;
  1617. PyFPE_START_PROTECT("in math_ldexp", return 0);
  1618. r = ldexp(x, (int)exp);
  1619. PyFPE_END_PROTECT(r);
  1620. if (Py_IS_INFINITY(r))
  1621. errno = ERANGE;
  1622. }
  1623. if (errno && is_error(r))
  1624. return NULL;
  1625. return PyFloat_FromDouble(r);
  1626. }
  1627. /*[clinic input]
  1628. math.modf
  1629. x: double
  1630. /
  1631. Return the fractional and integer parts of x.
  1632. Both results carry the sign of x and are floats.
  1633. [clinic start generated code]*/
  1634. static PyObject *
  1635. math_modf_impl(PyObject *module, double x)
  1636. /*[clinic end generated code: output=90cee0260014c3c0 input=b4cfb6786afd9035]*/
  1637. {
  1638. double y;
  1639. /* some platforms don't do the right thing for NaNs and
  1640. infinities, so we take care of special cases directly. */
  1641. if (!Py_IS_FINITE(x)) {
  1642. if (Py_IS_INFINITY(x))
  1643. return Py_BuildValue("(dd)", copysign(0., x), x);
  1644. else if (Py_IS_NAN(x))
  1645. return Py_BuildValue("(dd)", x, x);
  1646. }
  1647. errno = 0;
  1648. PyFPE_START_PROTECT("in math_modf", return 0);
  1649. x = modf(x, &y);
  1650. PyFPE_END_PROTECT(x);
  1651. return Py_BuildValue("(dd)", x, y);
  1652. }
  1653. /* A decent logarithm is easy to compute even for huge ints, but libm can't
  1654. do that by itself -- loghelper can. func is log or log10, and name is
  1655. "log" or "log10". Note that overflow of the result isn't possible: an int
  1656. can contain no more than INT_MAX * SHIFT bits, so has value certainly less
  1657. than 2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is
  1658. small enough to fit in an IEEE single. log and log10 are even smaller.
  1659. However, intermediate overflow is possible for an int if the number of bits
  1660. in that int is larger than PY_SSIZE_T_MAX. */
  1661. static PyObject*
  1662. loghelper(PyObject* arg, double (*func)(double), const char *funcname)
  1663. {
  1664. /* If it is int, do it ourselves. */
  1665. if (PyLong_Check(arg)) {
  1666. double x, result;
  1667. Py_ssize_t e;
  1668. /* Negative or zero inputs give a ValueError. */
  1669. if (Py_SIZE(arg) <= 0) {
  1670. PyErr_SetString(PyExc_ValueError,
  1671. "math domain error");
  1672. return NULL;
  1673. }
  1674. x = PyLong_AsDouble(arg);
  1675. if (x == -1.0 && PyErr_Occurred()) {
  1676. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  1677. return NULL;
  1678. /* Here the conversion to double overflowed, but it's possible
  1679. to compute the log anyway. Clear the exception and continue. */
  1680. PyErr_Clear();
  1681. x = _PyLong_Frexp((PyLongObject *)arg, &e);
  1682. if (x == -1.0 && PyErr_Occurred())
  1683. return NULL;
  1684. /* Value is ~= x * 2**e, so the log ~= log(x) + log(2) * e. */
  1685. result = func(x) + func(2.0) * e;
  1686. }
  1687. else
  1688. /* Successfully converted x to a double. */
  1689. result = func(x);
  1690. return PyFloat_FromDouble(result);
  1691. }
  1692. /* Else let libm handle it by itself. */
  1693. return math_1(arg, func, 0);
  1694. }
  1695. /*[clinic input]
  1696. math.log
  1697. x: object
  1698. [
  1699. base: object(c_default="NULL") = math.e
  1700. ]
  1701. /
  1702. Return the logarithm of x to the given base.
  1703. If the base not specified, returns the natural logarithm (base e) of x.
  1704. [clinic start generated code]*/
  1705. static PyObject *
  1706. math_log_impl(PyObject *module, PyObject *x, int group_right_1,
  1707. PyObject *base)
  1708. /*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
  1709. {
  1710. PyObject *num, *den;
  1711. PyObject *ans;
  1712. num = loghelper(x, m_log, "log");
  1713. if (num == NULL || base == NULL)
  1714. return num;
  1715. den = loghelper(base, m_log, "log");
  1716. if (den == NULL) {
  1717. Py_DECREF(num);
  1718. return NULL;
  1719. }
  1720. ans = PyNumber_TrueDivide(num, den);
  1721. Py_DECREF(num);
  1722. Py_DECREF(den);
  1723. return ans;
  1724. }
  1725. /*[clinic input]
  1726. math.log2
  1727. x: object
  1728. /
  1729. Return the base 2 logarithm of x.
  1730. [clinic start generated code]*/
  1731. static PyObject *
  1732. math_log2(PyObject *module, PyObject *x)
  1733. /*[clinic end generated code: output=5425899a4d5d6acb input=08321262bae4f39b]*/
  1734. {
  1735. return loghelper(x, m_log2, "log2");
  1736. }
  1737. /*[clinic input]
  1738. math.log10
  1739. x: object
  1740. /
  1741. Return the base 10 logarithm of x.
  1742. [clinic start generated code]*/
  1743. static PyObject *
  1744. math_log10(PyObject *module, PyObject *x)
  1745. /*[clinic end generated code: output=be72a64617df9c6f input=b2469d02c6469e53]*/
  1746. {
  1747. return loghelper(x, m_log10, "log10");
  1748. }
  1749. /*[clinic input]
  1750. math.fmod
  1751. x: double
  1752. y: double
  1753. /
  1754. Return fmod(x, y), according to platform C.
  1755. x % y may differ.
  1756. [clinic start generated code]*/
  1757. static PyObject *
  1758. math_fmod_impl(PyObject *module, double x, double y)
  1759. /*[clinic end generated code: output=7559d794343a27b5 input=4f84caa8cfc26a03]*/
  1760. {
  1761. double r;
  1762. /* fmod(x, +/-Inf) returns x for finite x. */
  1763. if (Py_IS_INFINITY(y) && Py_IS_FINITE(x))
  1764. return PyFloat_FromDouble(x);
  1765. errno = 0;
  1766. PyFPE_START_PROTECT("in math_fmod", return 0);
  1767. r = fmod(x, y);
  1768. PyFPE_END_PROTECT(r);
  1769. if (Py_IS_NAN(r)) {
  1770. if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
  1771. errno = EDOM;
  1772. else
  1773. errno = 0;
  1774. }
  1775. if (errno && is_error(r))
  1776. return NULL;
  1777. else
  1778. return PyFloat_FromDouble(r);
  1779. }
  1780. /*
  1781. Given an *n* length *vec* of values and a value *max*, compute:
  1782. max * sqrt(sum((x / max) ** 2 for x in vec))
  1783. The value of the *max* variable must be non-negative and
  1784. equal to the absolute value of the largest magnitude
  1785. entry in the vector. If n==0, then *max* should be 0.0.
  1786. If an infinity is present in the vec, *max* should be INF.
  1787. The *found_nan* variable indicates whether some member of
  1788. the *vec* is a NaN.
  1789. To improve accuracy and to increase the number of cases where
  1790. vector_norm() is commutative, we use a variant of Neumaier
  1791. summation specialized to exploit that we always know that
  1792. |csum| >= |x|.
  1793. The *csum* variable tracks the cumulative sum and *frac* tracks
  1794. the cumulative fractional errors at each step. Since this
  1795. variant assumes that |csum| >= |x| at each step, we establish
  1796. the precondition by starting the accumulation from 1.0 which
  1797. represents the largest possible value of (x/max)**2.
  1798. After the loop is finished, the initial 1.0 is subtracted out
  1799. for a net zero effect on the final sum. Since *csum* will be
  1800. greater than 1.0, the subtraction of 1.0 will not cause
  1801. fractional digits to be dropped from *csum*.
  1802. */
  1803. static inline double
  1804. vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
  1805. {
  1806. double x, csum = 1.0, oldcsum, frac = 0.0;
  1807. Py_ssize_t i;
  1808. if (Py_IS_INFINITY(max)) {
  1809. return max;
  1810. }
  1811. if (found_nan) {
  1812. return Py_NAN;
  1813. }
  1814. if (max == 0.0 || n <= 1) {
  1815. return max;
  1816. }
  1817. for (i=0 ; i < n ; i++) {
  1818. x = vec[i];
  1819. assert(Py_IS_FINITE(x) && fabs(x) <= max);
  1820. x /= max;
  1821. x = x*x;
  1822. oldcsum = csum;
  1823. csum += x;
  1824. assert(csum >= x);
  1825. frac += (oldcsum - csum) + x;
  1826. }
  1827. return max * sqrt(csum - 1.0 + frac);
  1828. }
  1829. #define NUM_STACK_ELEMS 16
  1830. /*[clinic input]
  1831. math.dist
  1832. p: object(subclass_of='&PyTuple_Type')
  1833. q: object(subclass_of='&PyTuple_Type')
  1834. /
  1835. Return the Euclidean distance between two points p and q.
  1836. The points should be specified as tuples of coordinates.
  1837. Both tuples must be the same size.
  1838. Roughly equivalent to:
  1839. sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
  1840. [clinic start generated code]*/
  1841. static PyObject *
  1842. math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
  1843. /*[clinic end generated code: output=56bd9538d06bbcfe input=937122eaa5f19272]*/
  1844. {
  1845. PyObject *item;
  1846. double max = 0.0;
  1847. double x, px, qx, result;
  1848. Py_ssize_t i, m, n;
  1849. int found_nan = 0;
  1850. double diffs_on_stack[NUM_STACK_ELEMS];
  1851. double *diffs = diffs_on_stack;
  1852. m = PyTuple_GET_SIZE(p);
  1853. n = PyTuple_GET_SIZE(q);
  1854. if (m != n) {
  1855. PyErr_SetString(PyExc_ValueError,
  1856. "both points must have the same number of dimensions");
  1857. return NULL;
  1858. }
  1859. if (n > NUM_STACK_ELEMS) {
  1860. diffs = (double *) PyObject_Malloc(n * sizeof(double));
  1861. if (diffs == NULL) {
  1862. return PyErr_NoMemory();
  1863. }
  1864. }
  1865. for (i=0 ; i<n ; i++) {
  1866. item = PyTuple_GET_ITEM(p, i);
  1867. ASSIGN_DOUBLE(px, item, error_exit);
  1868. item = PyTuple_GET_ITEM(q, i);
  1869. ASSIGN_DOUBLE(qx, item, error_exit);
  1870. x = fabs(px - qx);
  1871. diffs[i] = x;
  1872. found_nan |= Py_IS_NAN(x);
  1873. if (x > max) {
  1874. max = x;
  1875. }
  1876. }
  1877. result = vector_norm(n, diffs, max, found_nan);
  1878. if (diffs != diffs_on_stack) {
  1879. PyObject_Free(diffs);
  1880. }
  1881. return PyFloat_FromDouble(result);
  1882. error_exit:
  1883. if (diffs != diffs_on_stack) {
  1884. PyObject_Free(diffs);
  1885. }
  1886. return NULL;
  1887. }
  1888. /* AC: cannot convert yet, waiting for *args support */
  1889. static PyObject *
  1890. math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
  1891. {
  1892. Py_ssize_t i;
  1893. PyObject *item;
  1894. double max = 0.0;
  1895. double x, result;
  1896. int found_nan = 0;
  1897. double coord_on_stack[NUM_STACK_ELEMS];
  1898. double *coordinates = coord_on_stack;
  1899. if (nargs > NUM_STACK_ELEMS) {
  1900. coordinates = (double *) PyObject_Malloc(nargs * sizeof(double));
  1901. if (coordinates == NULL) {
  1902. return PyErr_NoMemory();
  1903. }
  1904. }
  1905. for (i = 0; i < nargs; i++) {
  1906. item = args[i];
  1907. ASSIGN_DOUBLE(x, item, error_exit);
  1908. x = fabs(x);
  1909. coordinates[i] = x;
  1910. found_nan |= Py_IS_NAN(x);
  1911. if (x > max) {
  1912. max = x;
  1913. }
  1914. }
  1915. result = vector_norm(nargs, coordinates, max, found_nan);
  1916. if (coordinates != coord_on_stack) {
  1917. PyObject_Free(coordinates);
  1918. }
  1919. return PyFloat_FromDouble(result);
  1920. error_exit:
  1921. if (coordinates != coord_on_stack) {
  1922. PyObject_Free(coordinates);
  1923. }
  1924. return NULL;
  1925. }
  1926. #undef NUM_STACK_ELEMS
  1927. PyDoc_STRVAR(math_hypot_doc,
  1928. "hypot(*coordinates) -> value\n\n\
  1929. Multidimensional Euclidean distance from the origin to a point.\n\
  1930. \n\
  1931. Roughly equivalent to:\n\
  1932. sqrt(sum(x**2 for x in coordinates))\n\
  1933. \n\
  1934. For a two dimensional point (x, y), gives the hypotenuse\n\
  1935. using the Pythagorean theorem: sqrt(x*x + y*y).\n\
  1936. \n\
  1937. For example, the hypotenuse of a 3/4/5 right triangle is:\n\
  1938. \n\
  1939. >>> hypot(3.0, 4.0)\n\
  1940. 5.0\n\
  1941. ");
  1942. /* pow can't use math_2, but needs its own wrapper: the problem is
  1943. that an infinite result can arise either as a result of overflow
  1944. (in which case OverflowError should be raised) or as a result of
  1945. e.g. 0.**-5. (for which ValueError needs to be raised.)
  1946. */
  1947. /*[clinic input]
  1948. math.pow
  1949. x: double
  1950. y: double
  1951. /
  1952. Return x**y (x to the power of y).
  1953. [clinic start generated code]*/
  1954. static PyObject *
  1955. math_pow_impl(PyObject *module, double x, double y)
  1956. /*[clinic end generated code: output=fff93e65abccd6b0 input=c26f1f6075088bfd]*/
  1957. {
  1958. double r;
  1959. int odd_y;
  1960. /* deal directly with IEEE specials, to cope with problems on various
  1961. platforms whose semantics don't exactly match C99 */
  1962. r = 0.; /* silence compiler warning */
  1963. if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) {
  1964. errno = 0;
  1965. if (Py_IS_NAN(x))
  1966. r = y == 0. ? 1. : x; /* NaN**0 = 1 */
  1967. else if (Py_IS_NAN(y))
  1968. r = x == 1. ? 1. : y; /* 1**NaN = 1 */
  1969. else if (Py_IS_INFINITY(x)) {
  1970. odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
  1971. if (y > 0.)
  1972. r = odd_y ? x : fabs(x);
  1973. else if (y == 0.)
  1974. r = 1.;
  1975. else /* y < 0. */
  1976. r = odd_y ? copysign(0., x) : 0.;
  1977. }
  1978. else if (Py_IS_INFINITY(y)) {
  1979. if (fabs(x) == 1.0)
  1980. r = 1.;
  1981. else if (y > 0. && fabs(x) > 1.0)
  1982. r = y;
  1983. else if (y < 0. && fabs(x) < 1.0) {
  1984. r = -y; /* result is +inf */
  1985. if (x == 0.) /* 0**-inf: divide-by-zero */
  1986. errno = EDOM;
  1987. }
  1988. else
  1989. r = 0.;
  1990. }
  1991. }
  1992. else {
  1993. /* let libm handle finite**finite */
  1994. errno = 0;
  1995. PyFPE_START_PROTECT("in math_pow", return 0);
  1996. r = pow(x, y);
  1997. PyFPE_END_PROTECT(r);
  1998. /* a NaN result should arise only from (-ve)**(finite
  1999. non-integer); in this case we want to raise ValueError. */
  2000. if (!Py_IS_FINITE(r)) {
  2001. if (Py_IS_NAN(r)) {
  2002. errno = EDOM;
  2003. }
  2004. /*
  2005. an infinite result here arises either from:
  2006. (A) (+/-0.)**negative (-> divide-by-zero)
  2007. (B) overflow of x**y with x and y finite
  2008. */
  2009. else if (Py_IS_INFINITY(r)) {
  2010. if (x == 0.)
  2011. errno = EDOM;
  2012. else
  2013. errno = ERANGE;
  2014. }
  2015. }
  2016. }
  2017. if (errno && is_error(r))
  2018. return NULL;
  2019. else
  2020. return PyFloat_FromDouble(r);
  2021. }
  2022. static const double degToRad = Py_MATH_PI / 180.0;
  2023. static const double radToDeg = 180.0 / Py_MATH_PI;
  2024. /*[clinic input]
  2025. math.degrees
  2026. x: double
  2027. /
  2028. Convert angle x from radians to degrees.
  2029. [clinic start generated code]*/
  2030. static PyObject *
  2031. math_degrees_impl(PyObject *module, double x)
  2032. /*[clinic end generated code: output=7fea78b294acd12f input=81e016555d6e3660]*/
  2033. {
  2034. return PyFloat_FromDouble(x * radToDeg);
  2035. }
  2036. /*[clinic input]
  2037. math.radians
  2038. x: double
  2039. /
  2040. Convert angle x from degrees to radians.
  2041. [clinic start generated code]*/
  2042. static PyObject *
  2043. math_radians_impl(PyObject *module, double x)
  2044. /*[clinic end generated code: output=34daa47caf9b1590 input=91626fc489fe3d63]*/
  2045. {
  2046. return PyFloat_FromDouble(x * degToRad);
  2047. }
  2048. /*[clinic input]
  2049. math.isfinite
  2050. x: double
  2051. /
  2052. Return True if x is neither an infinity nor a NaN, and False otherwise.
  2053. [clinic start generated code]*/
  2054. static PyObject *
  2055. math_isfinite_impl(PyObject *module, double x)
  2056. /*[clinic end generated code: output=8ba1f396440c9901 input=46967d254812e54a]*/
  2057. {
  2058. return PyBool_FromLong((long)Py_IS_FINITE(x));
  2059. }
  2060. /*[clinic input]
  2061. math.isnan
  2062. x: double
  2063. /
  2064. Return True if x is a NaN (not a number), and False otherwise.
  2065. [clinic start generated code]*/
  2066. static PyObject *
  2067. math_isnan_impl(PyObject *module, double x)
  2068. /*[clinic end generated code: output=f537b4d6df878c3e input=935891e66083f46a]*/
  2069. {
  2070. return PyBool_FromLong((long)Py_IS_NAN(x));
  2071. }
  2072. /*[clinic input]
  2073. math.isinf
  2074. x: double
  2075. /
  2076. Return True if x is a positive or negative infinity, and False otherwise.
  2077. [clinic start generated code]*/
  2078. static PyObject *
  2079. math_isinf_impl(PyObject *module, double x)
  2080. /*[clinic end generated code: output=9f00cbec4de7b06b input=32630e4212cf961f]*/
  2081. {
  2082. return PyBool_FromLong((long)Py_IS_INFINITY(x));
  2083. }
  2084. /*[clinic input]
  2085. math.isclose -> bool
  2086. a: double
  2087. b: double
  2088. *
  2089. rel_tol: double = 1e-09
  2090. maximum difference for being considered "close", relative to the
  2091. magnitude of the input values
  2092. abs_tol: double = 0.0
  2093. maximum difference for being considered "close", regardless of the
  2094. magnitude of the input values
  2095. Determine whether two floating point numbers are close in value.
  2096. Return True if a is close in value to b, and False otherwise.
  2097. For the values to be considered close, the difference between them
  2098. must be smaller than at least one of the tolerances.
  2099. -inf, inf and NaN behave similarly to the IEEE 754 Standard. That
  2100. is, NaN is not close to anything, even itself. inf and -inf are
  2101. only close to themselves.
  2102. [clinic start generated code]*/
  2103. static int
  2104. math_isclose_impl(PyObject *module, double a, double b, double rel_tol,
  2105. double abs_tol)
  2106. /*[clinic end generated code: output=b73070207511952d input=f28671871ea5bfba]*/
  2107. {
  2108. double diff = 0.0;
  2109. /* sanity check on the inputs */
  2110. if (rel_tol < 0.0 || abs_tol < 0.0 ) {
  2111. PyErr_SetString(PyExc_ValueError,
  2112. "tolerances must be non-negative");
  2113. return -1;
  2114. }
  2115. if ( a == b ) {
  2116. /* short circuit exact equality -- needed to catch two infinities of
  2117. the same sign. And perhaps speeds things up a bit sometimes.
  2118. */
  2119. return 1;
  2120. }
  2121. /* This catches the case of two infinities of opposite sign, or
  2122. one infinity and one finite number. Two infinities of opposite
  2123. sign would otherwise have an infinite relative tolerance.
  2124. Two infinities of the same sign are caught by the equality check
  2125. above.
  2126. */
  2127. if (Py_IS_INFINITY(a) || Py_IS_INFINITY(b)) {
  2128. return 0;
  2129. }
  2130. /* now do the regular computation
  2131. this is essentially the "weak" test from the Boost library
  2132. */
  2133. diff = fabs(b - a);
  2134. return (((diff <= fabs(rel_tol * b)) ||
  2135. (diff <= fabs(rel_tol * a))) ||
  2136. (diff <= abs_tol));
  2137. }
  2138. static inline int
  2139. _check_long_mult_overflow(long a, long b) {
  2140. /* From Python2's int_mul code:
  2141. Integer overflow checking for * is painful: Python tried a couple ways, but
  2142. they didn't work on all platforms, or failed in endcases (a product of
  2143. -sys.maxint-1 has been a particular pain).
  2144. Here's another way:
  2145. The native long product x*y is either exactly right or *way* off, being
  2146. just the last n bits of the true product, where n is the number of bits
  2147. in a long (the delivered product is the true product plus i*2**n for
  2148. some integer i).
  2149. The native double product (double)x * (double)y is subject to three
  2150. rounding errors: on a sizeof(long)==8 box, each cast to double can lose
  2151. info, and even on a sizeof(long)==4 box, the multiplication can lose info.
  2152. But, unlike the native long product, it's not in *range* trouble: even
  2153. if sizeof(long)==32 (256-bit longs), the product easily fits in the
  2154. dynamic range of a double. So the leading 50 (or so) bits of the double
  2155. product are correct.
  2156. We check these two ways against each other, and declare victory if they're
  2157. approximately the same. Else, because the native long product is the only
  2158. one that can lose catastrophic amounts of information, it's the native long
  2159. product that must have overflowed.
  2160. */
  2161. long longprod = (long)((unsigned long)a * b);
  2162. double doubleprod = (double)a * (double)b;
  2163. double doubled_longprod = (double)longprod;
  2164. if (doubled_longprod == doubleprod) {
  2165. return 0;
  2166. }
  2167. const double diff = doubled_longprod - doubleprod;
  2168. const double absdiff = diff >= 0.0 ? diff : -diff;
  2169. const double absprod = doubleprod >= 0.0 ? doubleprod : -doubleprod;
  2170. if (32.0 * absdiff <= absprod) {
  2171. return 0;
  2172. }
  2173. return 1;
  2174. }
  2175. /*[clinic input]
  2176. math.prod
  2177. iterable: object
  2178. /
  2179. *
  2180. start: object(c_default="NULL") = 1
  2181. Calculate the product of all the elements in the input iterable.
  2182. The default start value for the product is 1.
  2183. When the iterable is empty, return the start value. This function is
  2184. intended specifically for use with numeric values and may reject
  2185. non-numeric types.
  2186. [clinic start generated code]*/
  2187. static PyObject *
  2188. math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
  2189. /*[clinic end generated code: output=36153bedac74a198 input=4c5ab0682782ed54]*/
  2190. {
  2191. PyObject *result = start;
  2192. PyObject *temp, *item, *iter;
  2193. iter = PyObject_GetIter(iterable);
  2194. if (iter == NULL) {
  2195. return NULL;
  2196. }
  2197. if (result == NULL) {
  2198. result = PyLong_FromLong(1);
  2199. if (result == NULL) {
  2200. Py_DECREF(iter);
  2201. return NULL;
  2202. }
  2203. } else {
  2204. Py_INCREF(result);
  2205. }
  2206. #ifndef SLOW_PROD
  2207. /* Fast paths for integers keeping temporary products in C.
  2208. * Assumes all inputs are the same type.
  2209. * If the assumption fails, default to use PyObjects instead.
  2210. */
  2211. if (PyLong_CheckExact(result)) {
  2212. int overflow;
  2213. long i_result = PyLong_AsLongAndOverflow(result, &overflow);
  2214. /* If this already overflowed, don't even enter the loop. */
  2215. if (overflow == 0) {
  2216. Py_DECREF(result);
  2217. result = NULL;
  2218. }
  2219. /* Loop over all the items in the iterable until we finish, we overflow
  2220. * or we found a non integer element */
  2221. while(result == NULL) {
  2222. item = PyIter_Next(iter);
  2223. if (item == NULL) {
  2224. Py_DECREF(iter);
  2225. if (PyErr_Occurred()) {
  2226. return NULL;
  2227. }
  2228. return PyLong_FromLong(i_result);
  2229. }
  2230. if (PyLong_CheckExact(item)) {
  2231. long b = PyLong_AsLongAndOverflow(item, &overflow);
  2232. if (overflow == 0 && !_check_long_mult_overflow(i_result, b)) {
  2233. long x = i_result * b;
  2234. i_result = x;
  2235. Py_DECREF(item);
  2236. continue;
  2237. }
  2238. }
  2239. /* Either overflowed or is not an int.
  2240. * Restore real objects and process normally */
  2241. result = PyLong_FromLong(i_result);
  2242. if (result == NULL) {
  2243. Py_DECREF(item);
  2244. Py_DECREF(iter);
  2245. return NULL;
  2246. }
  2247. temp = PyNumber_Multiply(result, item);
  2248. Py_DECREF(result);
  2249. Py_DECREF(item);
  2250. result = temp;
  2251. if (result == NULL) {
  2252. Py_DECREF(iter);
  2253. return NULL;
  2254. }
  2255. }
  2256. }
  2257. /* Fast paths for floats keeping temporary products in C.
  2258. * Assumes all inputs are the same type.
  2259. * If the assumption fails, default to use PyObjects instead.
  2260. */
  2261. if (PyFloat_CheckExact(result)) {
  2262. double f_result = PyFloat_AS_DOUBLE(result);
  2263. Py_DECREF(result);
  2264. result = NULL;
  2265. while(result == NULL) {
  2266. item = PyIter_Next(iter);
  2267. if (item == NULL) {
  2268. Py_DECREF(iter);
  2269. if (PyErr_Occurred()) {
  2270. return NULL;
  2271. }
  2272. return PyFloat_FromDouble(f_result);
  2273. }
  2274. if (PyFloat_CheckExact(item)) {
  2275. f_result *= PyFloat_AS_DOUBLE(item);
  2276. Py_DECREF(item);
  2277. continue;
  2278. }
  2279. if (PyLong_CheckExact(item)) {
  2280. long value;
  2281. int overflow;
  2282. value = PyLong_AsLongAndOverflow(item, &overflow);
  2283. if (!overflow) {
  2284. f_result *= (double)value;
  2285. Py_DECREF(item);
  2286. continue;
  2287. }
  2288. }
  2289. result = PyFloat_FromDouble(f_result);
  2290. if (result == NULL) {
  2291. Py_DECREF(item);
  2292. Py_DECREF(iter);
  2293. return NULL;
  2294. }
  2295. temp = PyNumber_Multiply(result, item);
  2296. Py_DECREF(result);
  2297. Py_DECREF(item);
  2298. result = temp;
  2299. if (result == NULL) {
  2300. Py_DECREF(iter);
  2301. return NULL;
  2302. }
  2303. }
  2304. }
  2305. #endif
  2306. /* Consume rest of the iterable (if any) that could not be handled
  2307. * by specialized functions above.*/
  2308. for(;;) {
  2309. item = PyIter_Next(iter);
  2310. if (item == NULL) {
  2311. /* error, or end-of-sequence */
  2312. if (PyErr_Occurred()) {
  2313. Py_DECREF(result);
  2314. result = NULL;
  2315. }
  2316. break;
  2317. }
  2318. temp = PyNumber_Multiply(result, item);
  2319. Py_DECREF(result);
  2320. Py_DECREF(item);
  2321. result = temp;
  2322. if (result == NULL)
  2323. break;
  2324. }
  2325. Py_DECREF(iter);
  2326. return result;
  2327. }
  2328. static PyMethodDef math_methods[] = {
  2329. {"acos", math_acos, METH_O, math_acos_doc},
  2330. {"acosh", math_acosh, METH_O, math_acosh_doc},
  2331. {"asin", math_asin, METH_O, math_asin_doc},
  2332. {"asinh", math_asinh, METH_O, math_asinh_doc},
  2333. {"atan", math_atan, METH_O, math_atan_doc},
  2334. {"atan2", (PyCFunction)(void(*)(void))math_atan2, METH_FASTCALL, math_atan2_doc},
  2335. {"atanh", math_atanh, METH_O, math_atanh_doc},
  2336. MATH_CEIL_METHODDEF
  2337. {"copysign", (PyCFunction)(void(*)(void))math_copysign, METH_FASTCALL, math_copysign_doc},
  2338. {"cos", math_cos, METH_O, math_cos_doc},
  2339. {"cosh", math_cosh, METH_O, math_cosh_doc},
  2340. MATH_DEGREES_METHODDEF
  2341. MATH_DIST_METHODDEF
  2342. {"erf", math_erf, METH_O, math_erf_doc},
  2343. {"erfc", math_erfc, METH_O, math_erfc_doc},
  2344. {"exp", math_exp, METH_O, math_exp_doc},
  2345. {"expm1", math_expm1, METH_O, math_expm1_doc},
  2346. {"fabs", math_fabs, METH_O, math_fabs_doc},
  2347. MATH_FACTORIAL_METHODDEF
  2348. MATH_FLOOR_METHODDEF
  2349. MATH_FMOD_METHODDEF
  2350. MATH_FREXP_METHODDEF
  2351. MATH_FSUM_METHODDEF
  2352. {"gamma", math_gamma, METH_O, math_gamma_doc},
  2353. MATH_GCD_METHODDEF
  2354. {"hypot", (PyCFunction)(void(*)(void))math_hypot, METH_FASTCALL, math_hypot_doc},
  2355. MATH_ISCLOSE_METHODDEF
  2356. MATH_ISFINITE_METHODDEF
  2357. MATH_ISINF_METHODDEF
  2358. MATH_ISNAN_METHODDEF
  2359. MATH_LDEXP_METHODDEF
  2360. {"lgamma", math_lgamma, METH_O, math_lgamma_doc},
  2361. MATH_LOG_METHODDEF
  2362. {"log1p", math_log1p, METH_O, math_log1p_doc},
  2363. MATH_LOG10_METHODDEF
  2364. MATH_LOG2_METHODDEF
  2365. MATH_MODF_METHODDEF
  2366. MATH_POW_METHODDEF
  2367. MATH_RADIANS_METHODDEF
  2368. {"remainder", (PyCFunction)(void(*)(void))math_remainder, METH_FASTCALL, math_remainder_doc},
  2369. {"sin", math_sin, METH_O, math_sin_doc},
  2370. {"sinh", math_sinh, METH_O, math_sinh_doc},
  2371. {"sqrt", math_sqrt, METH_O, math_sqrt_doc},
  2372. {"tan", math_tan, METH_O, math_tan_doc},
  2373. {"tanh", math_tanh, METH_O, math_tanh_doc},
  2374. MATH_TRUNC_METHODDEF
  2375. MATH_PROD_METHODDEF
  2376. {NULL, NULL} /* sentinel */
  2377. };
  2378. PyDoc_STRVAR(module_doc,
  2379. "This module is always available. It provides access to the\n"
  2380. "mathematical functions defined by the C standard.");
  2381. static struct PyModuleDef mathmodule = {
  2382. PyModuleDef_HEAD_INIT,
  2383. "math",
  2384. module_doc,
  2385. -1,
  2386. math_methods,
  2387. NULL,
  2388. NULL,
  2389. NULL,
  2390. NULL
  2391. };
  2392. PyMODINIT_FUNC
  2393. PyInit_math(void)
  2394. {
  2395. PyObject *m;
  2396. m = PyModule_Create(&mathmodule);
  2397. if (m == NULL)
  2398. goto finally;
  2399. PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
  2400. PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
  2401. PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
  2402. PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
  2403. #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
  2404. PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));
  2405. #endif
  2406. finally:
  2407. return m;
  2408. }