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.

2601 lines
77 KiB

36 years ago
29 years ago
36 years ago
29 years ago
36 years ago
14 years ago
36 years ago
29 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 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 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
29 years ago
29 years ago
29 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
29 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. static double
  61. sinpi(double x)
  62. {
  63. double y, r;
  64. int n;
  65. /* this function should only ever be called for finite arguments */
  66. assert(Py_IS_FINITE(x));
  67. y = fmod(fabs(x), 2.0);
  68. n = (int)round(2.0*y);
  69. assert(0 <= n && n <= 4);
  70. switch (n) {
  71. case 0:
  72. r = sin(pi*y);
  73. break;
  74. case 1:
  75. r = cos(pi*(y-0.5));
  76. break;
  77. case 2:
  78. /* N.B. -sin(pi*(y-1.0)) is *not* equivalent: it would give
  79. -0.0 instead of 0.0 when y == 1.0. */
  80. r = sin(pi*(1.0-y));
  81. break;
  82. case 3:
  83. r = -cos(pi*(y-1.5));
  84. break;
  85. case 4:
  86. r = sin(pi*(y-2.0));
  87. break;
  88. default:
  89. Py_UNREACHABLE();
  90. }
  91. return copysign(1.0, x)*r;
  92. }
  93. /* Implementation of the real gamma function. In extensive but non-exhaustive
  94. random tests, this function proved accurate to within <= 10 ulps across the
  95. entire float domain. Note that accuracy may depend on the quality of the
  96. system math functions, the pow function in particular. Special cases
  97. follow C99 annex F. The parameters and method are tailored to platforms
  98. whose double format is the IEEE 754 binary64 format.
  99. Method: for x > 0.0 we use the Lanczos approximation with parameters N=13
  100. and g=6.024680040776729583740234375; these parameters are amongst those
  101. used by the Boost library. Following Boost (again), we re-express the
  102. Lanczos sum as a rational function, and compute it that way. The
  103. coefficients below were computed independently using MPFR, and have been
  104. double-checked against the coefficients in the Boost source code.
  105. For x < 0.0 we use the reflection formula.
  106. There's one minor tweak that deserves explanation: Lanczos' formula for
  107. Gamma(x) involves computing pow(x+g-0.5, x-0.5) / exp(x+g-0.5). For many x
  108. values, x+g-0.5 can be represented exactly. However, in cases where it
  109. can't be represented exactly the small error in x+g-0.5 can be magnified
  110. significantly by the pow and exp calls, especially for large x. A cheap
  111. correction is to multiply by (1 + e*g/(x+g-0.5)), where e is the error
  112. involved in the computation of x+g-0.5 (that is, e = computed value of
  113. x+g-0.5 - exact value of x+g-0.5). Here's the proof:
  114. Correction factor
  115. -----------------
  116. Write x+g-0.5 = y-e, where y is exactly representable as an IEEE 754
  117. double, and e is tiny. Then:
  118. pow(x+g-0.5,x-0.5)/exp(x+g-0.5) = pow(y-e, x-0.5)/exp(y-e)
  119. = pow(y, x-0.5)/exp(y) * C,
  120. where the correction_factor C is given by
  121. C = pow(1-e/y, x-0.5) * exp(e)
  122. Since e is tiny, pow(1-e/y, x-0.5) ~ 1-(x-0.5)*e/y, and exp(x) ~ 1+e, so:
  123. C ~ (1-(x-0.5)*e/y) * (1+e) ~ 1 + e*(y-(x-0.5))/y
  124. But y-(x-0.5) = g+e, and g+e ~ g. So we get C ~ 1 + e*g/y, and
  125. pow(x+g-0.5,x-0.5)/exp(x+g-0.5) ~ pow(y, x-0.5)/exp(y) * (1 + e*g/y),
  126. Note that for accuracy, when computing r*C it's better to do
  127. r + e*g/y*r;
  128. than
  129. r * (1 + e*g/y);
  130. since the addition in the latter throws away most of the bits of
  131. information in e*g/y.
  132. */
  133. #define LANCZOS_N 13
  134. static const double lanczos_g = 6.024680040776729583740234375;
  135. static const double lanczos_g_minus_half = 5.524680040776729583740234375;
  136. static const double lanczos_num_coeffs[LANCZOS_N] = {
  137. 23531376880.410759688572007674451636754734846804940,
  138. 42919803642.649098768957899047001988850926355848959,
  139. 35711959237.355668049440185451547166705960488635843,
  140. 17921034426.037209699919755754458931112671403265390,
  141. 6039542586.3520280050642916443072979210699388420708,
  142. 1439720407.3117216736632230727949123939715485786772,
  143. 248874557.86205415651146038641322942321632125127801,
  144. 31426415.585400194380614231628318205362874684987640,
  145. 2876370.6289353724412254090516208496135991145378768,
  146. 186056.26539522349504029498971604569928220784236328,
  147. 8071.6720023658162106380029022722506138218516325024,
  148. 210.82427775157934587250973392071336271166969580291,
  149. 2.5066282746310002701649081771338373386264310793408
  150. };
  151. /* denominator is x*(x+1)*...*(x+LANCZOS_N-2) */
  152. static const double lanczos_den_coeffs[LANCZOS_N] = {
  153. 0.0, 39916800.0, 120543840.0, 150917976.0, 105258076.0, 45995730.0,
  154. 13339535.0, 2637558.0, 357423.0, 32670.0, 1925.0, 66.0, 1.0};
  155. /* gamma values for small positive integers, 1 though NGAMMA_INTEGRAL */
  156. #define NGAMMA_INTEGRAL 23
  157. static const double gamma_integral[NGAMMA_INTEGRAL] = {
  158. 1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0,
  159. 3628800.0, 39916800.0, 479001600.0, 6227020800.0, 87178291200.0,
  160. 1307674368000.0, 20922789888000.0, 355687428096000.0,
  161. 6402373705728000.0, 121645100408832000.0, 2432902008176640000.0,
  162. 51090942171709440000.0, 1124000727777607680000.0,
  163. };
  164. /* Lanczos' sum L_g(x), for positive x */
  165. static double
  166. lanczos_sum(double x)
  167. {
  168. double num = 0.0, den = 0.0;
  169. int i;
  170. assert(x > 0.0);
  171. /* evaluate the rational function lanczos_sum(x). For large
  172. x, the obvious algorithm risks overflow, so we instead
  173. rescale the denominator and numerator of the rational
  174. function by x**(1-LANCZOS_N) and treat this as a
  175. rational function in 1/x. This also reduces the error for
  176. larger x values. The choice of cutoff point (5.0 below) is
  177. somewhat arbitrary; in tests, smaller cutoff values than
  178. this resulted in lower accuracy. */
  179. if (x < 5.0) {
  180. for (i = LANCZOS_N; --i >= 0; ) {
  181. num = num * x + lanczos_num_coeffs[i];
  182. den = den * x + lanczos_den_coeffs[i];
  183. }
  184. }
  185. else {
  186. for (i = 0; i < LANCZOS_N; i++) {
  187. num = num / x + lanczos_num_coeffs[i];
  188. den = den / x + lanczos_den_coeffs[i];
  189. }
  190. }
  191. return num/den;
  192. }
  193. /* Constant for +infinity, generated in the same way as float('inf'). */
  194. static double
  195. m_inf(void)
  196. {
  197. #ifndef PY_NO_SHORT_FLOAT_REPR
  198. return _Py_dg_infinity(0);
  199. #else
  200. return Py_HUGE_VAL;
  201. #endif
  202. }
  203. /* Constant nan value, generated in the same way as float('nan'). */
  204. /* We don't currently assume that Py_NAN is defined everywhere. */
  205. #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
  206. static double
  207. m_nan(void)
  208. {
  209. #ifndef PY_NO_SHORT_FLOAT_REPR
  210. return _Py_dg_stdnan(0);
  211. #else
  212. return Py_NAN;
  213. #endif
  214. }
  215. #endif
  216. static double
  217. m_tgamma(double x)
  218. {
  219. double absx, r, y, z, sqrtpow;
  220. /* special cases */
  221. if (!Py_IS_FINITE(x)) {
  222. if (Py_IS_NAN(x) || x > 0.0)
  223. return x; /* tgamma(nan) = nan, tgamma(inf) = inf */
  224. else {
  225. errno = EDOM;
  226. return Py_NAN; /* tgamma(-inf) = nan, invalid */
  227. }
  228. }
  229. if (x == 0.0) {
  230. errno = EDOM;
  231. /* tgamma(+-0.0) = +-inf, divide-by-zero */
  232. return copysign(Py_HUGE_VAL, x);
  233. }
  234. /* integer arguments */
  235. if (x == floor(x)) {
  236. if (x < 0.0) {
  237. errno = EDOM; /* tgamma(n) = nan, invalid for */
  238. return Py_NAN; /* negative integers n */
  239. }
  240. if (x <= NGAMMA_INTEGRAL)
  241. return gamma_integral[(int)x - 1];
  242. }
  243. absx = fabs(x);
  244. /* tiny arguments: tgamma(x) ~ 1/x for x near 0 */
  245. if (absx < 1e-20) {
  246. r = 1.0/x;
  247. if (Py_IS_INFINITY(r))
  248. errno = ERANGE;
  249. return r;
  250. }
  251. /* large arguments: assuming IEEE 754 doubles, tgamma(x) overflows for
  252. x > 200, and underflows to +-0.0 for x < -200, not a negative
  253. integer. */
  254. if (absx > 200.0) {
  255. if (x < 0.0) {
  256. return 0.0/sinpi(x);
  257. }
  258. else {
  259. errno = ERANGE;
  260. return Py_HUGE_VAL;
  261. }
  262. }
  263. y = absx + lanczos_g_minus_half;
  264. /* compute error in sum */
  265. if (absx > lanczos_g_minus_half) {
  266. /* note: the correction can be foiled by an optimizing
  267. compiler that (incorrectly) thinks that an expression like
  268. a + b - a - b can be optimized to 0.0. This shouldn't
  269. happen in a standards-conforming compiler. */
  270. double q = y - absx;
  271. z = q - lanczos_g_minus_half;
  272. }
  273. else {
  274. double q = y - lanczos_g_minus_half;
  275. z = q - absx;
  276. }
  277. z = z * lanczos_g / y;
  278. if (x < 0.0) {
  279. r = -pi / sinpi(absx) / absx * exp(y) / lanczos_sum(absx);
  280. r -= z * r;
  281. if (absx < 140.0) {
  282. r /= pow(y, absx - 0.5);
  283. }
  284. else {
  285. sqrtpow = pow(y, absx / 2.0 - 0.25);
  286. r /= sqrtpow;
  287. r /= sqrtpow;
  288. }
  289. }
  290. else {
  291. r = lanczos_sum(absx) / exp(y);
  292. r += z * r;
  293. if (absx < 140.0) {
  294. r *= pow(y, absx - 0.5);
  295. }
  296. else {
  297. sqrtpow = pow(y, absx / 2.0 - 0.25);
  298. r *= sqrtpow;
  299. r *= sqrtpow;
  300. }
  301. }
  302. if (Py_IS_INFINITY(r))
  303. errno = ERANGE;
  304. return r;
  305. }
  306. /*
  307. lgamma: natural log of the absolute value of the Gamma function.
  308. For large arguments, Lanczos' formula works extremely well here.
  309. */
  310. static double
  311. m_lgamma(double x)
  312. {
  313. double r;
  314. double absx;
  315. /* special cases */
  316. if (!Py_IS_FINITE(x)) {
  317. if (Py_IS_NAN(x))
  318. return x; /* lgamma(nan) = nan */
  319. else
  320. return Py_HUGE_VAL; /* lgamma(+-inf) = +inf */
  321. }
  322. /* integer arguments */
  323. if (x == floor(x) && x <= 2.0) {
  324. if (x <= 0.0) {
  325. errno = EDOM; /* lgamma(n) = inf, divide-by-zero for */
  326. return Py_HUGE_VAL; /* integers n <= 0 */
  327. }
  328. else {
  329. return 0.0; /* lgamma(1) = lgamma(2) = 0.0 */
  330. }
  331. }
  332. absx = fabs(x);
  333. /* tiny arguments: lgamma(x) ~ -log(fabs(x)) for small x */
  334. if (absx < 1e-20)
  335. return -log(absx);
  336. /* Lanczos' formula. We could save a fraction of a ulp in accuracy by
  337. having a second set of numerator coefficients for lanczos_sum that
  338. absorbed the exp(-lanczos_g) term, and throwing out the lanczos_g
  339. subtraction below; it's probably not worth it. */
  340. r = log(lanczos_sum(absx)) - lanczos_g;
  341. r += (absx - 0.5) * (log(absx + lanczos_g - 0.5) - 1);
  342. if (x < 0.0)
  343. /* Use reflection formula to get value for negative x. */
  344. r = logpi - log(fabs(sinpi(absx))) - log(absx) - r;
  345. if (Py_IS_INFINITY(r))
  346. errno = ERANGE;
  347. return r;
  348. }
  349. #if !defined(HAVE_ERF) || !defined(HAVE_ERFC)
  350. /*
  351. Implementations of the error function erf(x) and the complementary error
  352. function erfc(x).
  353. Method: we use a series approximation for erf for small x, and a continued
  354. fraction approximation for erfc(x) for larger x;
  355. combined with the relations erf(-x) = -erf(x) and erfc(x) = 1.0 - erf(x),
  356. this gives us erf(x) and erfc(x) for all x.
  357. The series expansion used is:
  358. erf(x) = x*exp(-x*x)/sqrt(pi) * [
  359. 2/1 + 4/3 x**2 + 8/15 x**4 + 16/105 x**6 + ...]
  360. The coefficient of x**(2k-2) here is 4**k*factorial(k)/factorial(2*k).
  361. This series converges well for smallish x, but slowly for larger x.
  362. The continued fraction expansion used is:
  363. erfc(x) = x*exp(-x*x)/sqrt(pi) * [1/(0.5 + x**2 -) 0.5/(2.5 + x**2 - )
  364. 3.0/(4.5 + x**2 - ) 7.5/(6.5 + x**2 - ) ...]
  365. after the first term, the general term has the form:
  366. k*(k-0.5)/(2*k+0.5 + x**2 - ...).
  367. This expansion converges fast for larger x, but convergence becomes
  368. infinitely slow as x approaches 0.0. The (somewhat naive) continued
  369. fraction evaluation algorithm used below also risks overflow for large x;
  370. but for large x, erfc(x) == 0.0 to within machine precision. (For
  371. example, erfc(30.0) is approximately 2.56e-393).
  372. Parameters: use series expansion for abs(x) < ERF_SERIES_CUTOFF and
  373. continued fraction expansion for ERF_SERIES_CUTOFF <= abs(x) <
  374. ERFC_CONTFRAC_CUTOFF. ERFC_SERIES_TERMS and ERFC_CONTFRAC_TERMS are the
  375. numbers of terms to use for the relevant expansions. */
  376. #define ERF_SERIES_CUTOFF 1.5
  377. #define ERF_SERIES_TERMS 25
  378. #define ERFC_CONTFRAC_CUTOFF 30.0
  379. #define ERFC_CONTFRAC_TERMS 50
  380. /*
  381. Error function, via power series.
  382. Given a finite float x, return an approximation to erf(x).
  383. Converges reasonably fast for small x.
  384. */
  385. static double
  386. m_erf_series(double x)
  387. {
  388. double x2, acc, fk, result;
  389. int i, saved_errno;
  390. x2 = x * x;
  391. acc = 0.0;
  392. fk = (double)ERF_SERIES_TERMS + 0.5;
  393. for (i = 0; i < ERF_SERIES_TERMS; i++) {
  394. acc = 2.0 + x2 * acc / fk;
  395. fk -= 1.0;
  396. }
  397. /* Make sure the exp call doesn't affect errno;
  398. see m_erfc_contfrac for more. */
  399. saved_errno = errno;
  400. result = acc * x * exp(-x2) / sqrtpi;
  401. errno = saved_errno;
  402. return result;
  403. }
  404. /*
  405. Complementary error function, via continued fraction expansion.
  406. Given a positive float x, return an approximation to erfc(x). Converges
  407. reasonably fast for x large (say, x > 2.0), and should be safe from
  408. overflow if x and nterms are not too large. On an IEEE 754 machine, with x
  409. <= 30.0, we're safe up to nterms = 100. For x >= 30.0, erfc(x) is smaller
  410. than the smallest representable nonzero float. */
  411. static double
  412. m_erfc_contfrac(double x)
  413. {
  414. double x2, a, da, p, p_last, q, q_last, b, result;
  415. int i, saved_errno;
  416. if (x >= ERFC_CONTFRAC_CUTOFF)
  417. return 0.0;
  418. x2 = x*x;
  419. a = 0.0;
  420. da = 0.5;
  421. p = 1.0; p_last = 0.0;
  422. q = da + x2; q_last = 1.0;
  423. for (i = 0; i < ERFC_CONTFRAC_TERMS; i++) {
  424. double temp;
  425. a += da;
  426. da += 2.0;
  427. b = da + x2;
  428. temp = p; p = b*p - a*p_last; p_last = temp;
  429. temp = q; q = b*q - a*q_last; q_last = temp;
  430. }
  431. /* Issue #8986: On some platforms, exp sets errno on underflow to zero;
  432. save the current errno value so that we can restore it later. */
  433. saved_errno = errno;
  434. result = p / q * x * exp(-x2) / sqrtpi;
  435. errno = saved_errno;
  436. return result;
  437. }
  438. #endif /* !defined(HAVE_ERF) || !defined(HAVE_ERFC) */
  439. /* Error function erf(x), for general x */
  440. static double
  441. m_erf(double x)
  442. {
  443. #ifdef HAVE_ERF
  444. return erf(x);
  445. #else
  446. double absx, cf;
  447. if (Py_IS_NAN(x))
  448. return x;
  449. absx = fabs(x);
  450. if (absx < ERF_SERIES_CUTOFF)
  451. return m_erf_series(x);
  452. else {
  453. cf = m_erfc_contfrac(absx);
  454. return x > 0.0 ? 1.0 - cf : cf - 1.0;
  455. }
  456. #endif
  457. }
  458. /* Complementary error function erfc(x), for general x. */
  459. static double
  460. m_erfc(double x)
  461. {
  462. #ifdef HAVE_ERFC
  463. return erfc(x);
  464. #else
  465. double absx, cf;
  466. if (Py_IS_NAN(x))
  467. return x;
  468. absx = fabs(x);
  469. if (absx < ERF_SERIES_CUTOFF)
  470. return 1.0 - m_erf_series(x);
  471. else {
  472. cf = m_erfc_contfrac(absx);
  473. return x > 0.0 ? cf : 2.0 - cf;
  474. }
  475. #endif
  476. }
  477. /*
  478. wrapper for atan2 that deals directly with special cases before
  479. delegating to the platform libm for the remaining cases. This
  480. is necessary to get consistent behaviour across platforms.
  481. Windows, FreeBSD and alpha Tru64 are amongst platforms that don't
  482. always follow C99.
  483. */
  484. static double
  485. m_atan2(double y, double x)
  486. {
  487. if (Py_IS_NAN(x) || Py_IS_NAN(y))
  488. return Py_NAN;
  489. if (Py_IS_INFINITY(y)) {
  490. if (Py_IS_INFINITY(x)) {
  491. if (copysign(1., x) == 1.)
  492. /* atan2(+-inf, +inf) == +-pi/4 */
  493. return copysign(0.25*Py_MATH_PI, y);
  494. else
  495. /* atan2(+-inf, -inf) == +-pi*3/4 */
  496. return copysign(0.75*Py_MATH_PI, y);
  497. }
  498. /* atan2(+-inf, x) == +-pi/2 for finite x */
  499. return copysign(0.5*Py_MATH_PI, y);
  500. }
  501. if (Py_IS_INFINITY(x) || y == 0.) {
  502. if (copysign(1., x) == 1.)
  503. /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
  504. return copysign(0., y);
  505. else
  506. /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
  507. return copysign(Py_MATH_PI, y);
  508. }
  509. return atan2(y, x);
  510. }
  511. /* IEEE 754-style remainder operation: x - n*y where n*y is the nearest
  512. multiple of y to x, taking n even in the case of a tie. Assuming an IEEE 754
  513. binary floating-point format, the result is always exact. */
  514. static double
  515. m_remainder(double x, double y)
  516. {
  517. /* Deal with most common case first. */
  518. if (Py_IS_FINITE(x) && Py_IS_FINITE(y)) {
  519. double absx, absy, c, m, r;
  520. if (y == 0.0) {
  521. return Py_NAN;
  522. }
  523. absx = fabs(x);
  524. absy = fabs(y);
  525. m = fmod(absx, absy);
  526. /*
  527. Warning: some subtlety here. What we *want* to know at this point is
  528. whether the remainder m is less than, equal to, or greater than half
  529. of absy. However, we can't do that comparison directly because we
  530. can't be sure that 0.5*absy is representable (the mutiplication
  531. might incur precision loss due to underflow). So instead we compare
  532. m with the complement c = absy - m: m < 0.5*absy if and only if m <
  533. c, and so on. The catch is that absy - m might also not be
  534. representable, but it turns out that it doesn't matter:
  535. - if m > 0.5*absy then absy - m is exactly representable, by
  536. Sterbenz's lemma, so m > c
  537. - if m == 0.5*absy then again absy - m is exactly representable
  538. and m == c
  539. - if m < 0.5*absy then either (i) 0.5*absy is exactly representable,
  540. in which case 0.5*absy < absy - m, so 0.5*absy <= c and hence m <
  541. c, or (ii) absy is tiny, either subnormal or in the lowest normal
  542. binade. Then absy - m is exactly representable and again m < c.
  543. */
  544. c = absy - m;
  545. if (m < c) {
  546. r = m;
  547. }
  548. else if (m > c) {
  549. r = -c;
  550. }
  551. else {
  552. /*
  553. Here absx is exactly halfway between two multiples of absy,
  554. and we need to choose the even multiple. x now has the form
  555. absx = n * absy + m
  556. for some integer n (recalling that m = 0.5*absy at this point).
  557. If n is even we want to return m; if n is odd, we need to
  558. return -m.
  559. So
  560. 0.5 * (absx - m) = (n/2) * absy
  561. and now reducing modulo absy gives us:
  562. | m, if n is odd
  563. fmod(0.5 * (absx - m), absy) = |
  564. | 0, if n is even
  565. Now m - 2.0 * fmod(...) gives the desired result: m
  566. if n is even, -m if m is odd.
  567. Note that all steps in fmod(0.5 * (absx - m), absy)
  568. will be computed exactly, with no rounding error
  569. introduced.
  570. */
  571. assert(m == c);
  572. r = m - 2.0 * fmod(0.5 * (absx - m), absy);
  573. }
  574. return copysign(1.0, x) * r;
  575. }
  576. /* Special values. */
  577. if (Py_IS_NAN(x)) {
  578. return x;
  579. }
  580. if (Py_IS_NAN(y)) {
  581. return y;
  582. }
  583. if (Py_IS_INFINITY(x)) {
  584. return Py_NAN;
  585. }
  586. assert(Py_IS_INFINITY(y));
  587. return x;
  588. }
  589. /*
  590. Various platforms (Solaris, OpenBSD) do nonstandard things for log(0),
  591. log(-ve), log(NaN). Here are wrappers for log and log10 that deal with
  592. special values directly, passing positive non-special values through to
  593. the system log/log10.
  594. */
  595. static double
  596. m_log(double x)
  597. {
  598. if (Py_IS_FINITE(x)) {
  599. if (x > 0.0)
  600. return log(x);
  601. errno = EDOM;
  602. if (x == 0.0)
  603. return -Py_HUGE_VAL; /* log(0) = -inf */
  604. else
  605. return Py_NAN; /* log(-ve) = nan */
  606. }
  607. else if (Py_IS_NAN(x))
  608. return x; /* log(nan) = nan */
  609. else if (x > 0.0)
  610. return x; /* log(inf) = inf */
  611. else {
  612. errno = EDOM;
  613. return Py_NAN; /* log(-inf) = nan */
  614. }
  615. }
  616. /*
  617. log2: log to base 2.
  618. Uses an algorithm that should:
  619. (a) produce exact results for powers of 2, and
  620. (b) give a monotonic log2 (for positive finite floats),
  621. assuming that the system log is monotonic.
  622. */
  623. static double
  624. m_log2(double x)
  625. {
  626. if (!Py_IS_FINITE(x)) {
  627. if (Py_IS_NAN(x))
  628. return x; /* log2(nan) = nan */
  629. else if (x > 0.0)
  630. return x; /* log2(+inf) = +inf */
  631. else {
  632. errno = EDOM;
  633. return Py_NAN; /* log2(-inf) = nan, invalid-operation */
  634. }
  635. }
  636. if (x > 0.0) {
  637. #ifdef HAVE_LOG2
  638. return log2(x);
  639. #else
  640. double m;
  641. int e;
  642. m = frexp(x, &e);
  643. /* We want log2(m * 2**e) == log(m) / log(2) + e. Care is needed when
  644. * x is just greater than 1.0: in that case e is 1, log(m) is negative,
  645. * and we get significant cancellation error from the addition of
  646. * log(m) / log(2) to e. The slight rewrite of the expression below
  647. * avoids this problem.
  648. */
  649. if (x >= 1.0) {
  650. return log(2.0 * m) / log(2.0) + (e - 1);
  651. }
  652. else {
  653. return log(m) / log(2.0) + e;
  654. }
  655. #endif
  656. }
  657. else if (x == 0.0) {
  658. errno = EDOM;
  659. return -Py_HUGE_VAL; /* log2(0) = -inf, divide-by-zero */
  660. }
  661. else {
  662. errno = EDOM;
  663. return Py_NAN; /* log2(-inf) = nan, invalid-operation */
  664. }
  665. }
  666. static double
  667. m_log10(double x)
  668. {
  669. if (Py_IS_FINITE(x)) {
  670. if (x > 0.0)
  671. return log10(x);
  672. errno = EDOM;
  673. if (x == 0.0)
  674. return -Py_HUGE_VAL; /* log10(0) = -inf */
  675. else
  676. return Py_NAN; /* log10(-ve) = nan */
  677. }
  678. else if (Py_IS_NAN(x))
  679. return x; /* log10(nan) = nan */
  680. else if (x > 0.0)
  681. return x; /* log10(inf) = inf */
  682. else {
  683. errno = EDOM;
  684. return Py_NAN; /* log10(-inf) = nan */
  685. }
  686. }
  687. /*[clinic input]
  688. math.gcd
  689. x as a: object
  690. y as b: object
  691. /
  692. greatest common divisor of x and y
  693. [clinic start generated code]*/
  694. static PyObject *
  695. math_gcd_impl(PyObject *module, PyObject *a, PyObject *b)
  696. /*[clinic end generated code: output=7b2e0c151bd7a5d8 input=c2691e57fb2a98fa]*/
  697. {
  698. PyObject *g;
  699. a = PyNumber_Index(a);
  700. if (a == NULL)
  701. return NULL;
  702. b = PyNumber_Index(b);
  703. if (b == NULL) {
  704. Py_DECREF(a);
  705. return NULL;
  706. }
  707. g = _PyLong_GCD(a, b);
  708. Py_DECREF(a);
  709. Py_DECREF(b);
  710. return g;
  711. }
  712. /* Call is_error when errno != 0, and where x is the result libm
  713. * returned. is_error will usually set up an exception and return
  714. * true (1), but may return false (0) without setting up an exception.
  715. */
  716. static int
  717. is_error(double x)
  718. {
  719. int result = 1; /* presumption of guilt */
  720. assert(errno); /* non-zero errno is a precondition for calling */
  721. if (errno == EDOM)
  722. PyErr_SetString(PyExc_ValueError, "math domain error");
  723. else if (errno == ERANGE) {
  724. /* ANSI C generally requires libm functions to set ERANGE
  725. * on overflow, but also generally *allows* them to set
  726. * ERANGE on underflow too. There's no consistency about
  727. * the latter across platforms.
  728. * Alas, C99 never requires that errno be set.
  729. * Here we suppress the underflow errors (libm functions
  730. * should return a zero on underflow, and +- HUGE_VAL on
  731. * overflow, so testing the result for zero suffices to
  732. * distinguish the cases).
  733. *
  734. * On some platforms (Ubuntu/ia64) it seems that errno can be
  735. * set to ERANGE for subnormal results that do *not* underflow
  736. * to zero. So to be safe, we'll ignore ERANGE whenever the
  737. * function result is less than one in absolute value.
  738. */
  739. if (fabs(x) < 1.0)
  740. result = 0;
  741. else
  742. PyErr_SetString(PyExc_OverflowError,
  743. "math range error");
  744. }
  745. else
  746. /* Unexpected math error */
  747. PyErr_SetFromErrno(PyExc_ValueError);
  748. return result;
  749. }
  750. /*
  751. math_1 is used to wrap a libm function f that takes a double
  752. argument and returns a double.
  753. The error reporting follows these rules, which are designed to do
  754. the right thing on C89/C99 platforms and IEEE 754/non IEEE 754
  755. platforms.
  756. - a NaN result from non-NaN inputs causes ValueError to be raised
  757. - an infinite result from finite inputs causes OverflowError to be
  758. raised if can_overflow is 1, or raises ValueError if can_overflow
  759. is 0.
  760. - if the result is finite and errno == EDOM then ValueError is
  761. raised
  762. - if the result is finite and nonzero and errno == ERANGE then
  763. OverflowError is raised
  764. The last rule is used to catch overflow on platforms which follow
  765. C89 but for which HUGE_VAL is not an infinity.
  766. For the majority of one-argument functions these rules are enough
  767. to ensure that Python's functions behave as specified in 'Annex F'
  768. of the C99 standard, with the 'invalid' and 'divide-by-zero'
  769. floating-point exceptions mapping to Python's ValueError and the
  770. 'overflow' floating-point exception mapping to OverflowError.
  771. math_1 only works for functions that don't have singularities *and*
  772. the possibility of overflow; fortunately, that covers everything we
  773. care about right now.
  774. */
  775. static PyObject *
  776. math_1_to_whatever(PyObject *arg, double (*func) (double),
  777. PyObject *(*from_double_func) (double),
  778. int can_overflow)
  779. {
  780. double x, r;
  781. x = PyFloat_AsDouble(arg);
  782. if (x == -1.0 && PyErr_Occurred())
  783. return NULL;
  784. errno = 0;
  785. PyFPE_START_PROTECT("in math_1", return 0);
  786. r = (*func)(x);
  787. PyFPE_END_PROTECT(r);
  788. if (Py_IS_NAN(r) && !Py_IS_NAN(x)) {
  789. PyErr_SetString(PyExc_ValueError,
  790. "math domain error"); /* invalid arg */
  791. return NULL;
  792. }
  793. if (Py_IS_INFINITY(r) && Py_IS_FINITE(x)) {
  794. if (can_overflow)
  795. PyErr_SetString(PyExc_OverflowError,
  796. "math range error"); /* overflow */
  797. else
  798. PyErr_SetString(PyExc_ValueError,
  799. "math domain error"); /* singularity */
  800. return NULL;
  801. }
  802. if (Py_IS_FINITE(r) && errno && is_error(r))
  803. /* this branch unnecessary on most platforms */
  804. return NULL;
  805. return (*from_double_func)(r);
  806. }
  807. /* variant of math_1, to be used when the function being wrapped is known to
  808. set errno properly (that is, errno = EDOM for invalid or divide-by-zero,
  809. errno = ERANGE for overflow). */
  810. static PyObject *
  811. math_1a(PyObject *arg, double (*func) (double))
  812. {
  813. double x, r;
  814. x = PyFloat_AsDouble(arg);
  815. if (x == -1.0 && PyErr_Occurred())
  816. return NULL;
  817. errno = 0;
  818. PyFPE_START_PROTECT("in math_1a", return 0);
  819. r = (*func)(x);
  820. PyFPE_END_PROTECT(r);
  821. if (errno && is_error(r))
  822. return NULL;
  823. return PyFloat_FromDouble(r);
  824. }
  825. /*
  826. math_2 is used to wrap a libm function f that takes two double
  827. arguments and returns a double.
  828. The error reporting follows these rules, which are designed to do
  829. the right thing on C89/C99 platforms and IEEE 754/non IEEE 754
  830. platforms.
  831. - a NaN result from non-NaN inputs causes ValueError to be raised
  832. - an infinite result from finite inputs causes OverflowError to be
  833. raised.
  834. - if the result is finite and errno == EDOM then ValueError is
  835. raised
  836. - if the result is finite and nonzero and errno == ERANGE then
  837. OverflowError is raised
  838. The last rule is used to catch overflow on platforms which follow
  839. C89 but for which HUGE_VAL is not an infinity.
  840. For most two-argument functions (copysign, fmod, hypot, atan2)
  841. these rules are enough to ensure that Python's functions behave as
  842. specified in 'Annex F' of the C99 standard, with the 'invalid' and
  843. 'divide-by-zero' floating-point exceptions mapping to Python's
  844. ValueError and the 'overflow' floating-point exception mapping to
  845. OverflowError.
  846. */
  847. static PyObject *
  848. math_1(PyObject *arg, double (*func) (double), int can_overflow)
  849. {
  850. return math_1_to_whatever(arg, func, PyFloat_FromDouble, can_overflow);
  851. }
  852. static PyObject *
  853. math_1_to_int(PyObject *arg, double (*func) (double), int can_overflow)
  854. {
  855. return math_1_to_whatever(arg, func, PyLong_FromDouble, can_overflow);
  856. }
  857. static PyObject *
  858. math_2(PyObject *const *args, Py_ssize_t nargs,
  859. double (*func) (double, double), const char *funcname)
  860. {
  861. double x, y, r;
  862. if (!_PyArg_CheckPositional(funcname, nargs, 2, 2))
  863. return NULL;
  864. x = PyFloat_AsDouble(args[0]);
  865. y = PyFloat_AsDouble(args[1]);
  866. if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
  867. return NULL;
  868. errno = 0;
  869. PyFPE_START_PROTECT("in math_2", return 0);
  870. r = (*func)(x, y);
  871. PyFPE_END_PROTECT(r);
  872. if (Py_IS_NAN(r)) {
  873. if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
  874. errno = EDOM;
  875. else
  876. errno = 0;
  877. }
  878. else if (Py_IS_INFINITY(r)) {
  879. if (Py_IS_FINITE(x) && Py_IS_FINITE(y))
  880. errno = ERANGE;
  881. else
  882. errno = 0;
  883. }
  884. if (errno && is_error(r))
  885. return NULL;
  886. else
  887. return PyFloat_FromDouble(r);
  888. }
  889. #define FUNC1(funcname, func, can_overflow, docstring) \
  890. static PyObject * math_##funcname(PyObject *self, PyObject *args) { \
  891. return math_1(args, func, can_overflow); \
  892. }\
  893. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  894. #define FUNC1A(funcname, func, docstring) \
  895. static PyObject * math_##funcname(PyObject *self, PyObject *args) { \
  896. return math_1a(args, func); \
  897. }\
  898. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  899. #define FUNC2(funcname, func, docstring) \
  900. static PyObject * math_##funcname(PyObject *self, PyObject *const *args, Py_ssize_t nargs) { \
  901. return math_2(args, nargs, func, #funcname); \
  902. }\
  903. PyDoc_STRVAR(math_##funcname##_doc, docstring);
  904. FUNC1(acos, acos, 0,
  905. "acos($module, x, /)\n--\n\n"
  906. "Return the arc cosine (measured in radians) of x.")
  907. FUNC1(acosh, m_acosh, 0,
  908. "acosh($module, x, /)\n--\n\n"
  909. "Return the inverse hyperbolic cosine of x.")
  910. FUNC1(asin, asin, 0,
  911. "asin($module, x, /)\n--\n\n"
  912. "Return the arc sine (measured in radians) of x.")
  913. FUNC1(asinh, m_asinh, 0,
  914. "asinh($module, x, /)\n--\n\n"
  915. "Return the inverse hyperbolic sine of x.")
  916. FUNC1(atan, atan, 0,
  917. "atan($module, x, /)\n--\n\n"
  918. "Return the arc tangent (measured in radians) of x.")
  919. FUNC2(atan2, m_atan2,
  920. "atan2($module, y, x, /)\n--\n\n"
  921. "Return the arc tangent (measured in radians) of y/x.\n\n"
  922. "Unlike atan(y/x), the signs of both x and y are considered.")
  923. FUNC1(atanh, m_atanh, 0,
  924. "atanh($module, x, /)\n--\n\n"
  925. "Return the inverse hyperbolic tangent of x.")
  926. /*[clinic input]
  927. math.ceil
  928. x as number: object
  929. /
  930. Return the ceiling of x as an Integral.
  931. This is the smallest integer >= x.
  932. [clinic start generated code]*/
  933. static PyObject *
  934. math_ceil(PyObject *module, PyObject *number)
  935. /*[clinic end generated code: output=6c3b8a78bc201c67 input=2725352806399cab]*/
  936. {
  937. _Py_IDENTIFIER(__ceil__);
  938. PyObject *method, *result;
  939. method = _PyObject_LookupSpecial(number, &PyId___ceil__);
  940. if (method == NULL) {
  941. if (PyErr_Occurred())
  942. return NULL;
  943. return math_1_to_int(number, ceil, 0);
  944. }
  945. result = _PyObject_CallNoArg(method);
  946. Py_DECREF(method);
  947. return result;
  948. }
  949. FUNC2(copysign, copysign,
  950. "copysign($module, x, y, /)\n--\n\n"
  951. "Return a float with the magnitude (absolute value) of x but the sign of y.\n\n"
  952. "On platforms that support signed zeros, copysign(1.0, -0.0)\n"
  953. "returns -1.0.\n")
  954. FUNC1(cos, cos, 0,
  955. "cos($module, x, /)\n--\n\n"
  956. "Return the cosine of x (measured in radians).")
  957. FUNC1(cosh, cosh, 1,
  958. "cosh($module, x, /)\n--\n\n"
  959. "Return the hyperbolic cosine of x.")
  960. FUNC1A(erf, m_erf,
  961. "erf($module, x, /)\n--\n\n"
  962. "Error function at x.")
  963. FUNC1A(erfc, m_erfc,
  964. "erfc($module, x, /)\n--\n\n"
  965. "Complementary error function at x.")
  966. FUNC1(exp, exp, 1,
  967. "exp($module, x, /)\n--\n\n"
  968. "Return e raised to the power of x.")
  969. FUNC1(expm1, m_expm1, 1,
  970. "expm1($module, x, /)\n--\n\n"
  971. "Return exp(x)-1.\n\n"
  972. "This function avoids the loss of precision involved in the direct "
  973. "evaluation of exp(x)-1 for small x.")
  974. FUNC1(fabs, fabs, 0,
  975. "fabs($module, x, /)\n--\n\n"
  976. "Return the absolute value of the float x.")
  977. /*[clinic input]
  978. math.floor
  979. x as number: object
  980. /
  981. Return the floor of x as an Integral.
  982. This is the largest integer <= x.
  983. [clinic start generated code]*/
  984. static PyObject *
  985. math_floor(PyObject *module, PyObject *number)
  986. /*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/
  987. {
  988. _Py_IDENTIFIER(__floor__);
  989. PyObject *method, *result;
  990. method = _PyObject_LookupSpecial(number, &PyId___floor__);
  991. if (method == NULL) {
  992. if (PyErr_Occurred())
  993. return NULL;
  994. return math_1_to_int(number, floor, 0);
  995. }
  996. result = _PyObject_CallNoArg(method);
  997. Py_DECREF(method);
  998. return result;
  999. }
  1000. FUNC1A(gamma, m_tgamma,
  1001. "gamma($module, x, /)\n--\n\n"
  1002. "Gamma function at x.")
  1003. FUNC1A(lgamma, m_lgamma,
  1004. "lgamma($module, x, /)\n--\n\n"
  1005. "Natural logarithm of absolute value of Gamma function at x.")
  1006. FUNC1(log1p, m_log1p, 0,
  1007. "log1p($module, x, /)\n--\n\n"
  1008. "Return the natural logarithm of 1+x (base e).\n\n"
  1009. "The result is computed in a way which is accurate for x near zero.")
  1010. FUNC2(remainder, m_remainder,
  1011. "remainder($module, x, y, /)\n--\n\n"
  1012. "Difference between x and the closest integer multiple of y.\n\n"
  1013. "Return x - n*y where n*y is the closest integer multiple of y.\n"
  1014. "In the case where x is exactly halfway between two multiples of\n"
  1015. "y, the nearest even value of n is used. The result is always exact.")
  1016. FUNC1(sin, sin, 0,
  1017. "sin($module, x, /)\n--\n\n"
  1018. "Return the sine of x (measured in radians).")
  1019. FUNC1(sinh, sinh, 1,
  1020. "sinh($module, x, /)\n--\n\n"
  1021. "Return the hyperbolic sine of x.")
  1022. FUNC1(sqrt, sqrt, 0,
  1023. "sqrt($module, x, /)\n--\n\n"
  1024. "Return the square root of x.")
  1025. FUNC1(tan, tan, 0,
  1026. "tan($module, x, /)\n--\n\n"
  1027. "Return the tangent of x (measured in radians).")
  1028. FUNC1(tanh, tanh, 0,
  1029. "tanh($module, x, /)\n--\n\n"
  1030. "Return the hyperbolic tangent of x.")
  1031. /* Precision summation function as msum() by Raymond Hettinger in
  1032. <http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/393090>,
  1033. enhanced with the exact partials sum and roundoff from Mark
  1034. Dickinson's post at <http://bugs.python.org/file10357/msum4.py>.
  1035. See those links for more details, proofs and other references.
  1036. Note 1: IEEE 754R floating point semantics are assumed,
  1037. but the current implementation does not re-establish special
  1038. value semantics across iterations (i.e. handling -Inf + Inf).
  1039. Note 2: No provision is made for intermediate overflow handling;
  1040. therefore, sum([1e+308, 1e-308, 1e+308]) returns 1e+308 while
  1041. sum([1e+308, 1e+308, 1e-308]) raises an OverflowError due to the
  1042. overflow of the first partial sum.
  1043. Note 3: The intermediate values lo, yr, and hi are declared volatile so
  1044. aggressive compilers won't algebraically reduce lo to always be exactly 0.0.
  1045. Also, the volatile declaration forces the values to be stored in memory as
  1046. regular doubles instead of extended long precision (80-bit) values. This
  1047. prevents double rounding because any addition or subtraction of two doubles
  1048. can be resolved exactly into double-sized hi and lo values. As long as the
  1049. hi value gets forced into a double before yr and lo are computed, the extra
  1050. bits in downstream extended precision operations (x87 for example) will be
  1051. exactly zero and therefore can be losslessly stored back into a double,
  1052. thereby preventing double rounding.
  1053. Note 4: A similar implementation is in Modules/cmathmodule.c.
  1054. Be sure to update both when making changes.
  1055. Note 5: The signature of math.fsum() differs from builtins.sum()
  1056. because the start argument doesn't make sense in the context of
  1057. accurate summation. Since the partials table is collapsed before
  1058. returning a result, sum(seq2, start=sum(seq1)) may not equal the
  1059. accurate result returned by sum(itertools.chain(seq1, seq2)).
  1060. */
  1061. #define NUM_PARTIALS 32 /* initial partials array size, on stack */
  1062. /* Extend the partials array p[] by doubling its size. */
  1063. static int /* non-zero on error */
  1064. _fsum_realloc(double **p_ptr, Py_ssize_t n,
  1065. double *ps, Py_ssize_t *m_ptr)
  1066. {
  1067. void *v = NULL;
  1068. Py_ssize_t m = *m_ptr;
  1069. m += m; /* double */
  1070. if (n < m && (size_t)m < ((size_t)PY_SSIZE_T_MAX / sizeof(double))) {
  1071. double *p = *p_ptr;
  1072. if (p == ps) {
  1073. v = PyMem_Malloc(sizeof(double) * m);
  1074. if (v != NULL)
  1075. memcpy(v, ps, sizeof(double) * n);
  1076. }
  1077. else
  1078. v = PyMem_Realloc(p, sizeof(double) * m);
  1079. }
  1080. if (v == NULL) { /* size overflow or no memory */
  1081. PyErr_SetString(PyExc_MemoryError, "math.fsum partials");
  1082. return 1;
  1083. }
  1084. *p_ptr = (double*) v;
  1085. *m_ptr = m;
  1086. return 0;
  1087. }
  1088. /* Full precision summation of a sequence of floats.
  1089. def msum(iterable):
  1090. partials = [] # sorted, non-overlapping partial sums
  1091. for x in iterable:
  1092. i = 0
  1093. for y in partials:
  1094. if abs(x) < abs(y):
  1095. x, y = y, x
  1096. hi = x + y
  1097. lo = y - (hi - x)
  1098. if lo:
  1099. partials[i] = lo
  1100. i += 1
  1101. x = hi
  1102. partials[i:] = [x]
  1103. return sum_exact(partials)
  1104. Rounded x+y stored in hi with the roundoff stored in lo. Together hi+lo
  1105. are exactly equal to x+y. The inner loop applies hi/lo summation to each
  1106. partial so that the list of partial sums remains exact.
  1107. Sum_exact() adds the partial sums exactly and correctly rounds the final
  1108. result (using the round-half-to-even rule). The items in partials remain
  1109. non-zero, non-special, non-overlapping and strictly increasing in
  1110. magnitude, but possibly not all having the same sign.
  1111. Depends on IEEE 754 arithmetic guarantees and half-even rounding.
  1112. */
  1113. /*[clinic input]
  1114. math.fsum
  1115. seq: object
  1116. /
  1117. Return an accurate floating point sum of values in the iterable seq.
  1118. Assumes IEEE-754 floating point arithmetic.
  1119. [clinic start generated code]*/
  1120. static PyObject *
  1121. math_fsum(PyObject *module, PyObject *seq)
  1122. /*[clinic end generated code: output=ba5c672b87fe34fc input=c51b7d8caf6f6e82]*/
  1123. {
  1124. PyObject *item, *iter, *sum = NULL;
  1125. Py_ssize_t i, j, n = 0, m = NUM_PARTIALS;
  1126. double x, y, t, ps[NUM_PARTIALS], *p = ps;
  1127. double xsave, special_sum = 0.0, inf_sum = 0.0;
  1128. volatile double hi, yr, lo;
  1129. iter = PyObject_GetIter(seq);
  1130. if (iter == NULL)
  1131. return NULL;
  1132. PyFPE_START_PROTECT("fsum", Py_DECREF(iter); return NULL)
  1133. for(;;) { /* for x in iterable */
  1134. assert(0 <= n && n <= m);
  1135. assert((m == NUM_PARTIALS && p == ps) ||
  1136. (m > NUM_PARTIALS && p != NULL));
  1137. item = PyIter_Next(iter);
  1138. if (item == NULL) {
  1139. if (PyErr_Occurred())
  1140. goto _fsum_error;
  1141. break;
  1142. }
  1143. x = PyFloat_AsDouble(item);
  1144. Py_DECREF(item);
  1145. if (PyErr_Occurred())
  1146. goto _fsum_error;
  1147. xsave = x;
  1148. for (i = j = 0; j < n; j++) { /* for y in partials */
  1149. y = p[j];
  1150. if (fabs(x) < fabs(y)) {
  1151. t = x; x = y; y = t;
  1152. }
  1153. hi = x + y;
  1154. yr = hi - x;
  1155. lo = y - yr;
  1156. if (lo != 0.0)
  1157. p[i++] = lo;
  1158. x = hi;
  1159. }
  1160. n = i; /* ps[i:] = [x] */
  1161. if (x != 0.0) {
  1162. if (! Py_IS_FINITE(x)) {
  1163. /* a nonfinite x could arise either as
  1164. a result of intermediate overflow, or
  1165. as a result of a nan or inf in the
  1166. summands */
  1167. if (Py_IS_FINITE(xsave)) {
  1168. PyErr_SetString(PyExc_OverflowError,
  1169. "intermediate overflow in fsum");
  1170. goto _fsum_error;
  1171. }
  1172. if (Py_IS_INFINITY(xsave))
  1173. inf_sum += xsave;
  1174. special_sum += xsave;
  1175. /* reset partials */
  1176. n = 0;
  1177. }
  1178. else if (n >= m && _fsum_realloc(&p, n, ps, &m))
  1179. goto _fsum_error;
  1180. else
  1181. p[n++] = x;
  1182. }
  1183. }
  1184. if (special_sum != 0.0) {
  1185. if (Py_IS_NAN(inf_sum))
  1186. PyErr_SetString(PyExc_ValueError,
  1187. "-inf + inf in fsum");
  1188. else
  1189. sum = PyFloat_FromDouble(special_sum);
  1190. goto _fsum_error;
  1191. }
  1192. hi = 0.0;
  1193. if (n > 0) {
  1194. hi = p[--n];
  1195. /* sum_exact(ps, hi) from the top, stop when the sum becomes
  1196. inexact. */
  1197. while (n > 0) {
  1198. x = hi;
  1199. y = p[--n];
  1200. assert(fabs(y) < fabs(x));
  1201. hi = x + y;
  1202. yr = hi - x;
  1203. lo = y - yr;
  1204. if (lo != 0.0)
  1205. break;
  1206. }
  1207. /* Make half-even rounding work across multiple partials.
  1208. Needed so that sum([1e-16, 1, 1e16]) will round-up the last
  1209. digit to two instead of down to zero (the 1e-16 makes the 1
  1210. slightly closer to two). With a potential 1 ULP rounding
  1211. error fixed-up, math.fsum() can guarantee commutativity. */
  1212. if (n > 0 && ((lo < 0.0 && p[n-1] < 0.0) ||
  1213. (lo > 0.0 && p[n-1] > 0.0))) {
  1214. y = lo * 2.0;
  1215. x = hi + y;
  1216. yr = x - hi;
  1217. if (y == yr)
  1218. hi = x;
  1219. }
  1220. }
  1221. sum = PyFloat_FromDouble(hi);
  1222. _fsum_error:
  1223. PyFPE_END_PROTECT(hi)
  1224. Py_DECREF(iter);
  1225. if (p != ps)
  1226. PyMem_Free(p);
  1227. return sum;
  1228. }
  1229. #undef NUM_PARTIALS
  1230. /* Return the smallest integer k such that n < 2**k, or 0 if n == 0.
  1231. * Equivalent to floor(lg(x))+1. Also equivalent to: bitwidth_of_type -
  1232. * count_leading_zero_bits(x)
  1233. */
  1234. /* XXX: This routine does more or less the same thing as
  1235. * bits_in_digit() in Objects/longobject.c. Someday it would be nice to
  1236. * consolidate them. On BSD, there's a library function called fls()
  1237. * that we could use, and GCC provides __builtin_clz().
  1238. */
  1239. static unsigned long
  1240. bit_length(unsigned long n)
  1241. {
  1242. unsigned long len = 0;
  1243. while (n != 0) {
  1244. ++len;
  1245. n >>= 1;
  1246. }
  1247. return len;
  1248. }
  1249. static unsigned long
  1250. count_set_bits(unsigned long n)
  1251. {
  1252. unsigned long count = 0;
  1253. while (n != 0) {
  1254. ++count;
  1255. n &= n - 1; /* clear least significant bit */
  1256. }
  1257. return count;
  1258. }
  1259. /* Divide-and-conquer factorial algorithm
  1260. *
  1261. * Based on the formula and pseudo-code provided at:
  1262. * http://www.luschny.de/math/factorial/binarysplitfact.html
  1263. *
  1264. * Faster algorithms exist, but they're more complicated and depend on
  1265. * a fast prime factorization algorithm.
  1266. *
  1267. * Notes on the algorithm
  1268. * ----------------------
  1269. *
  1270. * factorial(n) is written in the form 2**k * m, with m odd. k and m are
  1271. * computed separately, and then combined using a left shift.
  1272. *
  1273. * The function factorial_odd_part computes the odd part m (i.e., the greatest
  1274. * odd divisor) of factorial(n), using the formula:
  1275. *
  1276. * factorial_odd_part(n) =
  1277. *
  1278. * product_{i >= 0} product_{0 < j <= n / 2**i, j odd} j
  1279. *
  1280. * Example: factorial_odd_part(20) =
  1281. *
  1282. * (1) *
  1283. * (1) *
  1284. * (1 * 3 * 5) *
  1285. * (1 * 3 * 5 * 7 * 9)
  1286. * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
  1287. *
  1288. * Here i goes from large to small: the first term corresponds to i=4 (any
  1289. * larger i gives an empty product), and the last term corresponds to i=0.
  1290. * Each term can be computed from the last by multiplying by the extra odd
  1291. * numbers required: e.g., to get from the penultimate term to the last one,
  1292. * we multiply by (11 * 13 * 15 * 17 * 19).
  1293. *
  1294. * To see a hint of why this formula works, here are the same numbers as above
  1295. * but with the even parts (i.e., the appropriate powers of 2) included. For
  1296. * each subterm in the product for i, we multiply that subterm by 2**i:
  1297. *
  1298. * factorial(20) =
  1299. *
  1300. * (16) *
  1301. * (8) *
  1302. * (4 * 12 * 20) *
  1303. * (2 * 6 * 10 * 14 * 18) *
  1304. * (1 * 3 * 5 * 7 * 9 * 11 * 13 * 15 * 17 * 19)
  1305. *
  1306. * The factorial_partial_product function computes the product of all odd j in
  1307. * range(start, stop) for given start and stop. It's used to compute the
  1308. * partial products like (11 * 13 * 15 * 17 * 19) in the example above. It
  1309. * operates recursively, repeatedly splitting the range into two roughly equal
  1310. * pieces until the subranges are small enough to be computed using only C
  1311. * integer arithmetic.
  1312. *
  1313. * The two-valuation k (i.e., the exponent of the largest power of 2 dividing
  1314. * the factorial) is computed independently in the main math_factorial
  1315. * function. By standard results, its value is:
  1316. *
  1317. * two_valuation = n//2 + n//4 + n//8 + ....
  1318. *
  1319. * It can be shown (e.g., by complete induction on n) that two_valuation is
  1320. * equal to n - count_set_bits(n), where count_set_bits(n) gives the number of
  1321. * '1'-bits in the binary expansion of n.
  1322. */
  1323. /* factorial_partial_product: Compute product(range(start, stop, 2)) using
  1324. * divide and conquer. Assumes start and stop are odd and stop > start.
  1325. * max_bits must be >= bit_length(stop - 2). */
  1326. static PyObject *
  1327. factorial_partial_product(unsigned long start, unsigned long stop,
  1328. unsigned long max_bits)
  1329. {
  1330. unsigned long midpoint, num_operands;
  1331. PyObject *left = NULL, *right = NULL, *result = NULL;
  1332. /* If the return value will fit an unsigned long, then we can
  1333. * multiply in a tight, fast loop where each multiply is O(1).
  1334. * Compute an upper bound on the number of bits required to store
  1335. * the answer.
  1336. *
  1337. * Storing some integer z requires floor(lg(z))+1 bits, which is
  1338. * conveniently the value returned by bit_length(z). The
  1339. * product x*y will require at most
  1340. * bit_length(x) + bit_length(y) bits to store, based
  1341. * on the idea that lg product = lg x + lg y.
  1342. *
  1343. * We know that stop - 2 is the largest number to be multiplied. From
  1344. * there, we have: bit_length(answer) <= num_operands *
  1345. * bit_length(stop - 2)
  1346. */
  1347. num_operands = (stop - start) / 2;
  1348. /* The "num_operands <= 8 * SIZEOF_LONG" check guards against the
  1349. * unlikely case of an overflow in num_operands * max_bits. */
  1350. if (num_operands <= 8 * SIZEOF_LONG &&
  1351. num_operands * max_bits <= 8 * SIZEOF_LONG) {
  1352. unsigned long j, total;
  1353. for (total = start, j = start + 2; j < stop; j += 2)
  1354. total *= j;
  1355. return PyLong_FromUnsignedLong(total);
  1356. }
  1357. /* find midpoint of range(start, stop), rounded up to next odd number. */
  1358. midpoint = (start + num_operands) | 1;
  1359. left = factorial_partial_product(start, midpoint,
  1360. bit_length(midpoint - 2));
  1361. if (left == NULL)
  1362. goto error;
  1363. right = factorial_partial_product(midpoint, stop, max_bits);
  1364. if (right == NULL)
  1365. goto error;
  1366. result = PyNumber_Multiply(left, right);
  1367. error:
  1368. Py_XDECREF(left);
  1369. Py_XDECREF(right);
  1370. return result;
  1371. }
  1372. /* factorial_odd_part: compute the odd part of factorial(n). */
  1373. static PyObject *
  1374. factorial_odd_part(unsigned long n)
  1375. {
  1376. long i;
  1377. unsigned long v, lower, upper;
  1378. PyObject *partial, *tmp, *inner, *outer;
  1379. inner = PyLong_FromLong(1);
  1380. if (inner == NULL)
  1381. return NULL;
  1382. outer = inner;
  1383. Py_INCREF(outer);
  1384. upper = 3;
  1385. for (i = bit_length(n) - 2; i >= 0; i--) {
  1386. v = n >> i;
  1387. if (v <= 2)
  1388. continue;
  1389. lower = upper;
  1390. /* (v + 1) | 1 = least odd integer strictly larger than n / 2**i */
  1391. upper = (v + 1) | 1;
  1392. /* Here inner is the product of all odd integers j in the range (0,
  1393. n/2**(i+1)]. The factorial_partial_product call below gives the
  1394. product of all odd integers j in the range (n/2**(i+1), n/2**i]. */
  1395. partial = factorial_partial_product(lower, upper, bit_length(upper-2));
  1396. /* inner *= partial */
  1397. if (partial == NULL)
  1398. goto error;
  1399. tmp = PyNumber_Multiply(inner, partial);
  1400. Py_DECREF(partial);
  1401. if (tmp == NULL)
  1402. goto error;
  1403. Py_DECREF(inner);
  1404. inner = tmp;
  1405. /* Now inner is the product of all odd integers j in the range (0,
  1406. n/2**i], giving the inner product in the formula above. */
  1407. /* outer *= inner; */
  1408. tmp = PyNumber_Multiply(outer, inner);
  1409. if (tmp == NULL)
  1410. goto error;
  1411. Py_DECREF(outer);
  1412. outer = tmp;
  1413. }
  1414. Py_DECREF(inner);
  1415. return outer;
  1416. error:
  1417. Py_DECREF(outer);
  1418. Py_DECREF(inner);
  1419. return NULL;
  1420. }
  1421. /* Lookup table for small factorial values */
  1422. static const unsigned long SmallFactorials[] = {
  1423. 1, 1, 2, 6, 24, 120, 720, 5040, 40320,
  1424. 362880, 3628800, 39916800, 479001600,
  1425. #if SIZEOF_LONG >= 8
  1426. 6227020800, 87178291200, 1307674368000,
  1427. 20922789888000, 355687428096000, 6402373705728000,
  1428. 121645100408832000, 2432902008176640000
  1429. #endif
  1430. };
  1431. /*[clinic input]
  1432. math.factorial
  1433. x as arg: object
  1434. /
  1435. Find x!.
  1436. Raise a ValueError if x is negative or non-integral.
  1437. [clinic start generated code]*/
  1438. static PyObject *
  1439. math_factorial(PyObject *module, PyObject *arg)
  1440. /*[clinic end generated code: output=6686f26fae00e9ca input=6d1c8105c0d91fb4]*/
  1441. {
  1442. long x;
  1443. int overflow;
  1444. PyObject *result, *odd_part, *two_valuation, *pyint_form;
  1445. if (PyFloat_Check(arg)) {
  1446. PyObject *lx;
  1447. double dx = PyFloat_AS_DOUBLE((PyFloatObject *)arg);
  1448. if (!(Py_IS_FINITE(dx) && dx == floor(dx))) {
  1449. PyErr_SetString(PyExc_ValueError,
  1450. "factorial() only accepts integral values");
  1451. return NULL;
  1452. }
  1453. lx = PyLong_FromDouble(dx);
  1454. if (lx == NULL)
  1455. return NULL;
  1456. x = PyLong_AsLongAndOverflow(lx, &overflow);
  1457. Py_DECREF(lx);
  1458. }
  1459. else {
  1460. pyint_form = PyNumber_Index(arg);
  1461. if (pyint_form == NULL) {
  1462. return NULL;
  1463. }
  1464. x = PyLong_AsLongAndOverflow(pyint_form, &overflow);
  1465. Py_DECREF(pyint_form);
  1466. }
  1467. if (x == -1 && PyErr_Occurred()) {
  1468. return NULL;
  1469. }
  1470. else if (overflow == 1) {
  1471. PyErr_Format(PyExc_OverflowError,
  1472. "factorial() argument should not exceed %ld",
  1473. LONG_MAX);
  1474. return NULL;
  1475. }
  1476. else if (overflow == -1 || x < 0) {
  1477. PyErr_SetString(PyExc_ValueError,
  1478. "factorial() not defined for negative values");
  1479. return NULL;
  1480. }
  1481. /* use lookup table if x is small */
  1482. if (x < (long)Py_ARRAY_LENGTH(SmallFactorials))
  1483. return PyLong_FromUnsignedLong(SmallFactorials[x]);
  1484. /* else express in the form odd_part * 2**two_valuation, and compute as
  1485. odd_part << two_valuation. */
  1486. odd_part = factorial_odd_part(x);
  1487. if (odd_part == NULL)
  1488. return NULL;
  1489. two_valuation = PyLong_FromLong(x - count_set_bits(x));
  1490. if (two_valuation == NULL) {
  1491. Py_DECREF(odd_part);
  1492. return NULL;
  1493. }
  1494. result = PyNumber_Lshift(odd_part, two_valuation);
  1495. Py_DECREF(two_valuation);
  1496. Py_DECREF(odd_part);
  1497. return result;
  1498. }
  1499. /*[clinic input]
  1500. math.trunc
  1501. x: object
  1502. /
  1503. Truncates the Real x to the nearest Integral toward 0.
  1504. Uses the __trunc__ magic method.
  1505. [clinic start generated code]*/
  1506. static PyObject *
  1507. math_trunc(PyObject *module, PyObject *x)
  1508. /*[clinic end generated code: output=34b9697b707e1031 input=2168b34e0a09134d]*/
  1509. {
  1510. _Py_IDENTIFIER(__trunc__);
  1511. PyObject *trunc, *result;
  1512. if (Py_TYPE(x)->tp_dict == NULL) {
  1513. if (PyType_Ready(Py_TYPE(x)) < 0)
  1514. return NULL;
  1515. }
  1516. trunc = _PyObject_LookupSpecial(x, &PyId___trunc__);
  1517. if (trunc == NULL) {
  1518. if (!PyErr_Occurred())
  1519. PyErr_Format(PyExc_TypeError,
  1520. "type %.100s doesn't define __trunc__ method",
  1521. Py_TYPE(x)->tp_name);
  1522. return NULL;
  1523. }
  1524. result = _PyObject_CallNoArg(trunc);
  1525. Py_DECREF(trunc);
  1526. return result;
  1527. }
  1528. /*[clinic input]
  1529. math.frexp
  1530. x: double
  1531. /
  1532. Return the mantissa and exponent of x, as pair (m, e).
  1533. m is a float and e is an int, such that x = m * 2.**e.
  1534. If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.
  1535. [clinic start generated code]*/
  1536. static PyObject *
  1537. math_frexp_impl(PyObject *module, double x)
  1538. /*[clinic end generated code: output=03e30d252a15ad4a input=96251c9e208bc6e9]*/
  1539. {
  1540. int i;
  1541. /* deal with special cases directly, to sidestep platform
  1542. differences */
  1543. if (Py_IS_NAN(x) || Py_IS_INFINITY(x) || !x) {
  1544. i = 0;
  1545. }
  1546. else {
  1547. PyFPE_START_PROTECT("in math_frexp", return 0);
  1548. x = frexp(x, &i);
  1549. PyFPE_END_PROTECT(x);
  1550. }
  1551. return Py_BuildValue("(di)", x, i);
  1552. }
  1553. /*[clinic input]
  1554. math.ldexp
  1555. x: double
  1556. i: object
  1557. /
  1558. Return x * (2**i).
  1559. This is essentially the inverse of frexp().
  1560. [clinic start generated code]*/
  1561. static PyObject *
  1562. math_ldexp_impl(PyObject *module, double x, PyObject *i)
  1563. /*[clinic end generated code: output=b6892f3c2df9cc6a input=17d5970c1a40a8c1]*/
  1564. {
  1565. double r;
  1566. long exp;
  1567. int overflow;
  1568. if (PyLong_Check(i)) {
  1569. /* on overflow, replace exponent with either LONG_MAX
  1570. or LONG_MIN, depending on the sign. */
  1571. exp = PyLong_AsLongAndOverflow(i, &overflow);
  1572. if (exp == -1 && PyErr_Occurred())
  1573. return NULL;
  1574. if (overflow)
  1575. exp = overflow < 0 ? LONG_MIN : LONG_MAX;
  1576. }
  1577. else {
  1578. PyErr_SetString(PyExc_TypeError,
  1579. "Expected an int as second argument to ldexp.");
  1580. return NULL;
  1581. }
  1582. if (x == 0. || !Py_IS_FINITE(x)) {
  1583. /* NaNs, zeros and infinities are returned unchanged */
  1584. r = x;
  1585. errno = 0;
  1586. } else if (exp > INT_MAX) {
  1587. /* overflow */
  1588. r = copysign(Py_HUGE_VAL, x);
  1589. errno = ERANGE;
  1590. } else if (exp < INT_MIN) {
  1591. /* underflow to +-0 */
  1592. r = copysign(0., x);
  1593. errno = 0;
  1594. } else {
  1595. errno = 0;
  1596. PyFPE_START_PROTECT("in math_ldexp", return 0);
  1597. r = ldexp(x, (int)exp);
  1598. PyFPE_END_PROTECT(r);
  1599. if (Py_IS_INFINITY(r))
  1600. errno = ERANGE;
  1601. }
  1602. if (errno && is_error(r))
  1603. return NULL;
  1604. return PyFloat_FromDouble(r);
  1605. }
  1606. /*[clinic input]
  1607. math.modf
  1608. x: double
  1609. /
  1610. Return the fractional and integer parts of x.
  1611. Both results carry the sign of x and are floats.
  1612. [clinic start generated code]*/
  1613. static PyObject *
  1614. math_modf_impl(PyObject *module, double x)
  1615. /*[clinic end generated code: output=90cee0260014c3c0 input=b4cfb6786afd9035]*/
  1616. {
  1617. double y;
  1618. /* some platforms don't do the right thing for NaNs and
  1619. infinities, so we take care of special cases directly. */
  1620. if (!Py_IS_FINITE(x)) {
  1621. if (Py_IS_INFINITY(x))
  1622. return Py_BuildValue("(dd)", copysign(0., x), x);
  1623. else if (Py_IS_NAN(x))
  1624. return Py_BuildValue("(dd)", x, x);
  1625. }
  1626. errno = 0;
  1627. PyFPE_START_PROTECT("in math_modf", return 0);
  1628. x = modf(x, &y);
  1629. PyFPE_END_PROTECT(x);
  1630. return Py_BuildValue("(dd)", x, y);
  1631. }
  1632. /* A decent logarithm is easy to compute even for huge ints, but libm can't
  1633. do that by itself -- loghelper can. func is log or log10, and name is
  1634. "log" or "log10". Note that overflow of the result isn't possible: an int
  1635. can contain no more than INT_MAX * SHIFT bits, so has value certainly less
  1636. than 2**(2**64 * 2**16) == 2**2**80, and log2 of that is 2**80, which is
  1637. small enough to fit in an IEEE single. log and log10 are even smaller.
  1638. However, intermediate overflow is possible for an int if the number of bits
  1639. in that int is larger than PY_SSIZE_T_MAX. */
  1640. static PyObject*
  1641. loghelper(PyObject* arg, double (*func)(double), const char *funcname)
  1642. {
  1643. /* If it is int, do it ourselves. */
  1644. if (PyLong_Check(arg)) {
  1645. double x, result;
  1646. Py_ssize_t e;
  1647. /* Negative or zero inputs give a ValueError. */
  1648. if (Py_SIZE(arg) <= 0) {
  1649. PyErr_SetString(PyExc_ValueError,
  1650. "math domain error");
  1651. return NULL;
  1652. }
  1653. x = PyLong_AsDouble(arg);
  1654. if (x == -1.0 && PyErr_Occurred()) {
  1655. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  1656. return NULL;
  1657. /* Here the conversion to double overflowed, but it's possible
  1658. to compute the log anyway. Clear the exception and continue. */
  1659. PyErr_Clear();
  1660. x = _PyLong_Frexp((PyLongObject *)arg, &e);
  1661. if (x == -1.0 && PyErr_Occurred())
  1662. return NULL;
  1663. /* Value is ~= x * 2**e, so the log ~= log(x) + log(2) * e. */
  1664. result = func(x) + func(2.0) * e;
  1665. }
  1666. else
  1667. /* Successfully converted x to a double. */
  1668. result = func(x);
  1669. return PyFloat_FromDouble(result);
  1670. }
  1671. /* Else let libm handle it by itself. */
  1672. return math_1(arg, func, 0);
  1673. }
  1674. /*[clinic input]
  1675. math.log
  1676. x: object
  1677. [
  1678. base: object(c_default="NULL") = math.e
  1679. ]
  1680. /
  1681. Return the logarithm of x to the given base.
  1682. If the base not specified, returns the natural logarithm (base e) of x.
  1683. [clinic start generated code]*/
  1684. static PyObject *
  1685. math_log_impl(PyObject *module, PyObject *x, int group_right_1,
  1686. PyObject *base)
  1687. /*[clinic end generated code: output=7b5a39e526b73fc9 input=0f62d5726cbfebbd]*/
  1688. {
  1689. PyObject *num, *den;
  1690. PyObject *ans;
  1691. num = loghelper(x, m_log, "log");
  1692. if (num == NULL || base == NULL)
  1693. return num;
  1694. den = loghelper(base, m_log, "log");
  1695. if (den == NULL) {
  1696. Py_DECREF(num);
  1697. return NULL;
  1698. }
  1699. ans = PyNumber_TrueDivide(num, den);
  1700. Py_DECREF(num);
  1701. Py_DECREF(den);
  1702. return ans;
  1703. }
  1704. /*[clinic input]
  1705. math.log2
  1706. x: object
  1707. /
  1708. Return the base 2 logarithm of x.
  1709. [clinic start generated code]*/
  1710. static PyObject *
  1711. math_log2(PyObject *module, PyObject *x)
  1712. /*[clinic end generated code: output=5425899a4d5d6acb input=08321262bae4f39b]*/
  1713. {
  1714. return loghelper(x, m_log2, "log2");
  1715. }
  1716. /*[clinic input]
  1717. math.log10
  1718. x: object
  1719. /
  1720. Return the base 10 logarithm of x.
  1721. [clinic start generated code]*/
  1722. static PyObject *
  1723. math_log10(PyObject *module, PyObject *x)
  1724. /*[clinic end generated code: output=be72a64617df9c6f input=b2469d02c6469e53]*/
  1725. {
  1726. return loghelper(x, m_log10, "log10");
  1727. }
  1728. /*[clinic input]
  1729. math.fmod
  1730. x: double
  1731. y: double
  1732. /
  1733. Return fmod(x, y), according to platform C.
  1734. x % y may differ.
  1735. [clinic start generated code]*/
  1736. static PyObject *
  1737. math_fmod_impl(PyObject *module, double x, double y)
  1738. /*[clinic end generated code: output=7559d794343a27b5 input=4f84caa8cfc26a03]*/
  1739. {
  1740. double r;
  1741. /* fmod(x, +/-Inf) returns x for finite x. */
  1742. if (Py_IS_INFINITY(y) && Py_IS_FINITE(x))
  1743. return PyFloat_FromDouble(x);
  1744. errno = 0;
  1745. PyFPE_START_PROTECT("in math_fmod", return 0);
  1746. r = fmod(x, y);
  1747. PyFPE_END_PROTECT(r);
  1748. if (Py_IS_NAN(r)) {
  1749. if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
  1750. errno = EDOM;
  1751. else
  1752. errno = 0;
  1753. }
  1754. if (errno && is_error(r))
  1755. return NULL;
  1756. else
  1757. return PyFloat_FromDouble(r);
  1758. }
  1759. /*
  1760. Given an *n* length *vec* of values and a value *max*, compute:
  1761. max * sqrt(sum((x / max) ** 2 for x in vec))
  1762. The value of the *max* variable must be non-negative and
  1763. equal to the absolute value of the largest magnitude
  1764. entry in the vector. If n==0, then *max* should be 0.0.
  1765. If an infinity is present in the vec, *max* should be INF.
  1766. The *found_nan* variable indicates whether some member of
  1767. the *vec* is a NaN.
  1768. To improve accuracy and to increase the number of cases where
  1769. vector_norm() is commutative, we use a variant of Neumaier
  1770. summation specialized to exploit that we always know that
  1771. |csum| >= |x|.
  1772. The *csum* variable tracks the cumulative sum and *frac* tracks
  1773. the cumulative fractional errors at each step. Since this
  1774. variant assumes that |csum| >= |x| at each step, we establish
  1775. the precondition by starting the accumulation from 1.0 which
  1776. represents the largest possible value of (x/max)**2.
  1777. After the loop is finished, the initial 1.0 is subtracted out
  1778. for a net zero effect on the final sum. Since *csum* will be
  1779. greater than 1.0, the subtraction of 1.0 will not cause
  1780. fractional digits to be dropped from *csum*.
  1781. */
  1782. static inline double
  1783. vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
  1784. {
  1785. double x, csum = 1.0, oldcsum, frac = 0.0;
  1786. Py_ssize_t i;
  1787. if (Py_IS_INFINITY(max)) {
  1788. return max;
  1789. }
  1790. if (found_nan) {
  1791. return Py_NAN;
  1792. }
  1793. if (max == 0.0 || n <= 1) {
  1794. return max;
  1795. }
  1796. for (i=0 ; i < n ; i++) {
  1797. x = vec[i];
  1798. assert(Py_IS_FINITE(x) && fabs(x) <= max);
  1799. x /= max;
  1800. x = x*x;
  1801. oldcsum = csum;
  1802. csum += x;
  1803. assert(csum >= x);
  1804. frac += (oldcsum - csum) + x;
  1805. }
  1806. return max * sqrt(csum - 1.0 + frac);
  1807. }
  1808. #define NUM_STACK_ELEMS 16
  1809. /*[clinic input]
  1810. math.dist
  1811. p: object(subclass_of='&PyTuple_Type')
  1812. q: object(subclass_of='&PyTuple_Type')
  1813. /
  1814. Return the Euclidean distance between two points p and q.
  1815. The points should be specified as tuples of coordinates.
  1816. Both tuples must be the same size.
  1817. Roughly equivalent to:
  1818. sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
  1819. [clinic start generated code]*/
  1820. static PyObject *
  1821. math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
  1822. /*[clinic end generated code: output=56bd9538d06bbcfe input=937122eaa5f19272]*/
  1823. {
  1824. PyObject *item;
  1825. double max = 0.0;
  1826. double x, px, qx, result;
  1827. Py_ssize_t i, m, n;
  1828. int found_nan = 0;
  1829. double diffs_on_stack[NUM_STACK_ELEMS];
  1830. double *diffs = diffs_on_stack;
  1831. m = PyTuple_GET_SIZE(p);
  1832. n = PyTuple_GET_SIZE(q);
  1833. if (m != n) {
  1834. PyErr_SetString(PyExc_ValueError,
  1835. "both points must have the same number of dimensions");
  1836. return NULL;
  1837. }
  1838. if (n > NUM_STACK_ELEMS) {
  1839. diffs = (double *) PyObject_Malloc(n * sizeof(double));
  1840. if (diffs == NULL) {
  1841. return PyErr_NoMemory();
  1842. }
  1843. }
  1844. for (i=0 ; i<n ; i++) {
  1845. item = PyTuple_GET_ITEM(p, i);
  1846. if (PyFloat_CheckExact(item)) {
  1847. px = PyFloat_AS_DOUBLE(item);
  1848. }
  1849. else if (PyLong_CheckExact(item)) {
  1850. px = PyLong_AsDouble(item);
  1851. if (px == -1.0 && PyErr_Occurred()) {
  1852. goto error_exit;
  1853. }
  1854. }
  1855. else {
  1856. px = PyFloat_AsDouble(item);
  1857. if (px == -1.0 && PyErr_Occurred()) {
  1858. goto error_exit;
  1859. }
  1860. }
  1861. item = PyTuple_GET_ITEM(q, i);
  1862. if (PyFloat_CheckExact(item)) {
  1863. qx = PyFloat_AS_DOUBLE(item);
  1864. }
  1865. else if (PyLong_CheckExact(item)) {
  1866. qx = PyLong_AsDouble(item);
  1867. if (qx == -1.0 && PyErr_Occurred()) {
  1868. goto error_exit;
  1869. }
  1870. }
  1871. else {
  1872. qx = PyFloat_AsDouble(item);
  1873. if (qx == -1.0 && PyErr_Occurred()) {
  1874. goto error_exit;
  1875. }
  1876. }
  1877. x = fabs(px - qx);
  1878. diffs[i] = x;
  1879. found_nan |= Py_IS_NAN(x);
  1880. if (x > max) {
  1881. max = x;
  1882. }
  1883. }
  1884. result = vector_norm(n, diffs, max, found_nan);
  1885. if (diffs != diffs_on_stack) {
  1886. PyObject_Free(diffs);
  1887. }
  1888. return PyFloat_FromDouble(result);
  1889. error_exit:
  1890. if (diffs != diffs_on_stack) {
  1891. PyObject_Free(diffs);
  1892. }
  1893. return NULL;
  1894. }
  1895. /* AC: cannot convert yet, waiting for *args support */
  1896. static PyObject *
  1897. math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
  1898. {
  1899. Py_ssize_t i;
  1900. PyObject *item;
  1901. double max = 0.0;
  1902. double x, result;
  1903. int found_nan = 0;
  1904. double coord_on_stack[NUM_STACK_ELEMS];
  1905. double *coordinates = coord_on_stack;
  1906. if (nargs > NUM_STACK_ELEMS) {
  1907. coordinates = (double *) PyObject_Malloc(nargs * sizeof(double));
  1908. if (coordinates == NULL) {
  1909. return PyErr_NoMemory();
  1910. }
  1911. }
  1912. for (i = 0; i < nargs; i++) {
  1913. item = args[i];
  1914. if (PyFloat_CheckExact(item)) {
  1915. x = PyFloat_AS_DOUBLE(item);
  1916. }
  1917. else if (PyLong_CheckExact(item)) {
  1918. x = PyLong_AsDouble(item);
  1919. if (x == -1.0 && PyErr_Occurred()) {
  1920. goto error_exit;
  1921. }
  1922. }
  1923. else {
  1924. x = PyFloat_AsDouble(item);
  1925. if (x == -1.0 && PyErr_Occurred()) {
  1926. goto error_exit;
  1927. }
  1928. }
  1929. x = fabs(x);
  1930. coordinates[i] = x;
  1931. found_nan |= Py_IS_NAN(x);
  1932. if (x > max) {
  1933. max = x;
  1934. }
  1935. }
  1936. result = vector_norm(nargs, coordinates, max, found_nan);
  1937. if (coordinates != coord_on_stack) {
  1938. PyObject_Free(coordinates);
  1939. }
  1940. return PyFloat_FromDouble(result);
  1941. error_exit:
  1942. if (coordinates != coord_on_stack) {
  1943. PyObject_Free(coordinates);
  1944. }
  1945. return NULL;
  1946. }
  1947. #undef NUM_STACK_ELEMS
  1948. PyDoc_STRVAR(math_hypot_doc,
  1949. "hypot(*coordinates) -> value\n\n\
  1950. Multidimensional Euclidean distance from the origin to a point.\n\
  1951. \n\
  1952. Roughly equivalent to:\n\
  1953. sqrt(sum(x**2 for x in coordinates))\n\
  1954. \n\
  1955. For a two dimensional point (x, y), gives the hypotenuse\n\
  1956. using the Pythagorean theorem: sqrt(x*x + y*y).\n\
  1957. \n\
  1958. For example, the hypotenuse of a 3/4/5 right triangle is:\n\
  1959. \n\
  1960. >>> hypot(3.0, 4.0)\n\
  1961. 5.0\n\
  1962. ");
  1963. /* pow can't use math_2, but needs its own wrapper: the problem is
  1964. that an infinite result can arise either as a result of overflow
  1965. (in which case OverflowError should be raised) or as a result of
  1966. e.g. 0.**-5. (for which ValueError needs to be raised.)
  1967. */
  1968. /*[clinic input]
  1969. math.pow
  1970. x: double
  1971. y: double
  1972. /
  1973. Return x**y (x to the power of y).
  1974. [clinic start generated code]*/
  1975. static PyObject *
  1976. math_pow_impl(PyObject *module, double x, double y)
  1977. /*[clinic end generated code: output=fff93e65abccd6b0 input=c26f1f6075088bfd]*/
  1978. {
  1979. double r;
  1980. int odd_y;
  1981. /* deal directly with IEEE specials, to cope with problems on various
  1982. platforms whose semantics don't exactly match C99 */
  1983. r = 0.; /* silence compiler warning */
  1984. if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) {
  1985. errno = 0;
  1986. if (Py_IS_NAN(x))
  1987. r = y == 0. ? 1. : x; /* NaN**0 = 1 */
  1988. else if (Py_IS_NAN(y))
  1989. r = x == 1. ? 1. : y; /* 1**NaN = 1 */
  1990. else if (Py_IS_INFINITY(x)) {
  1991. odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
  1992. if (y > 0.)
  1993. r = odd_y ? x : fabs(x);
  1994. else if (y == 0.)
  1995. r = 1.;
  1996. else /* y < 0. */
  1997. r = odd_y ? copysign(0., x) : 0.;
  1998. }
  1999. else if (Py_IS_INFINITY(y)) {
  2000. if (fabs(x) == 1.0)
  2001. r = 1.;
  2002. else if (y > 0. && fabs(x) > 1.0)
  2003. r = y;
  2004. else if (y < 0. && fabs(x) < 1.0) {
  2005. r = -y; /* result is +inf */
  2006. if (x == 0.) /* 0**-inf: divide-by-zero */
  2007. errno = EDOM;
  2008. }
  2009. else
  2010. r = 0.;
  2011. }
  2012. }
  2013. else {
  2014. /* let libm handle finite**finite */
  2015. errno = 0;
  2016. PyFPE_START_PROTECT("in math_pow", return 0);
  2017. r = pow(x, y);
  2018. PyFPE_END_PROTECT(r);
  2019. /* a NaN result should arise only from (-ve)**(finite
  2020. non-integer); in this case we want to raise ValueError. */
  2021. if (!Py_IS_FINITE(r)) {
  2022. if (Py_IS_NAN(r)) {
  2023. errno = EDOM;
  2024. }
  2025. /*
  2026. an infinite result here arises either from:
  2027. (A) (+/-0.)**negative (-> divide-by-zero)
  2028. (B) overflow of x**y with x and y finite
  2029. */
  2030. else if (Py_IS_INFINITY(r)) {
  2031. if (x == 0.)
  2032. errno = EDOM;
  2033. else
  2034. errno = ERANGE;
  2035. }
  2036. }
  2037. }
  2038. if (errno && is_error(r))
  2039. return NULL;
  2040. else
  2041. return PyFloat_FromDouble(r);
  2042. }
  2043. static const double degToRad = Py_MATH_PI / 180.0;
  2044. static const double radToDeg = 180.0 / Py_MATH_PI;
  2045. /*[clinic input]
  2046. math.degrees
  2047. x: double
  2048. /
  2049. Convert angle x from radians to degrees.
  2050. [clinic start generated code]*/
  2051. static PyObject *
  2052. math_degrees_impl(PyObject *module, double x)
  2053. /*[clinic end generated code: output=7fea78b294acd12f input=81e016555d6e3660]*/
  2054. {
  2055. return PyFloat_FromDouble(x * radToDeg);
  2056. }
  2057. /*[clinic input]
  2058. math.radians
  2059. x: double
  2060. /
  2061. Convert angle x from degrees to radians.
  2062. [clinic start generated code]*/
  2063. static PyObject *
  2064. math_radians_impl(PyObject *module, double x)
  2065. /*[clinic end generated code: output=34daa47caf9b1590 input=91626fc489fe3d63]*/
  2066. {
  2067. return PyFloat_FromDouble(x * degToRad);
  2068. }
  2069. /*[clinic input]
  2070. math.isfinite
  2071. x: double
  2072. /
  2073. Return True if x is neither an infinity nor a NaN, and False otherwise.
  2074. [clinic start generated code]*/
  2075. static PyObject *
  2076. math_isfinite_impl(PyObject *module, double x)
  2077. /*[clinic end generated code: output=8ba1f396440c9901 input=46967d254812e54a]*/
  2078. {
  2079. return PyBool_FromLong((long)Py_IS_FINITE(x));
  2080. }
  2081. /*[clinic input]
  2082. math.isnan
  2083. x: double
  2084. /
  2085. Return True if x is a NaN (not a number), and False otherwise.
  2086. [clinic start generated code]*/
  2087. static PyObject *
  2088. math_isnan_impl(PyObject *module, double x)
  2089. /*[clinic end generated code: output=f537b4d6df878c3e input=935891e66083f46a]*/
  2090. {
  2091. return PyBool_FromLong((long)Py_IS_NAN(x));
  2092. }
  2093. /*[clinic input]
  2094. math.isinf
  2095. x: double
  2096. /
  2097. Return True if x is a positive or negative infinity, and False otherwise.
  2098. [clinic start generated code]*/
  2099. static PyObject *
  2100. math_isinf_impl(PyObject *module, double x)
  2101. /*[clinic end generated code: output=9f00cbec4de7b06b input=32630e4212cf961f]*/
  2102. {
  2103. return PyBool_FromLong((long)Py_IS_INFINITY(x));
  2104. }
  2105. /*[clinic input]
  2106. math.isclose -> bool
  2107. a: double
  2108. b: double
  2109. *
  2110. rel_tol: double = 1e-09
  2111. maximum difference for being considered "close", relative to the
  2112. magnitude of the input values
  2113. abs_tol: double = 0.0
  2114. maximum difference for being considered "close", regardless of the
  2115. magnitude of the input values
  2116. Determine whether two floating point numbers are close in value.
  2117. Return True if a is close in value to b, and False otherwise.
  2118. For the values to be considered close, the difference between them
  2119. must be smaller than at least one of the tolerances.
  2120. -inf, inf and NaN behave similarly to the IEEE 754 Standard. That
  2121. is, NaN is not close to anything, even itself. inf and -inf are
  2122. only close to themselves.
  2123. [clinic start generated code]*/
  2124. static int
  2125. math_isclose_impl(PyObject *module, double a, double b, double rel_tol,
  2126. double abs_tol)
  2127. /*[clinic end generated code: output=b73070207511952d input=f28671871ea5bfba]*/
  2128. {
  2129. double diff = 0.0;
  2130. /* sanity check on the inputs */
  2131. if (rel_tol < 0.0 || abs_tol < 0.0 ) {
  2132. PyErr_SetString(PyExc_ValueError,
  2133. "tolerances must be non-negative");
  2134. return -1;
  2135. }
  2136. if ( a == b ) {
  2137. /* short circuit exact equality -- needed to catch two infinities of
  2138. the same sign. And perhaps speeds things up a bit sometimes.
  2139. */
  2140. return 1;
  2141. }
  2142. /* This catches the case of two infinities of opposite sign, or
  2143. one infinity and one finite number. Two infinities of opposite
  2144. sign would otherwise have an infinite relative tolerance.
  2145. Two infinities of the same sign are caught by the equality check
  2146. above.
  2147. */
  2148. if (Py_IS_INFINITY(a) || Py_IS_INFINITY(b)) {
  2149. return 0;
  2150. }
  2151. /* now do the regular computation
  2152. this is essentially the "weak" test from the Boost library
  2153. */
  2154. diff = fabs(b - a);
  2155. return (((diff <= fabs(rel_tol * b)) ||
  2156. (diff <= fabs(rel_tol * a))) ||
  2157. (diff <= abs_tol));
  2158. }
  2159. static PyMethodDef math_methods[] = {
  2160. {"acos", math_acos, METH_O, math_acos_doc},
  2161. {"acosh", math_acosh, METH_O, math_acosh_doc},
  2162. {"asin", math_asin, METH_O, math_asin_doc},
  2163. {"asinh", math_asinh, METH_O, math_asinh_doc},
  2164. {"atan", math_atan, METH_O, math_atan_doc},
  2165. {"atan2", (PyCFunction)(void(*)(void))math_atan2, METH_FASTCALL, math_atan2_doc},
  2166. {"atanh", math_atanh, METH_O, math_atanh_doc},
  2167. MATH_CEIL_METHODDEF
  2168. {"copysign", (PyCFunction)(void(*)(void))math_copysign, METH_FASTCALL, math_copysign_doc},
  2169. {"cos", math_cos, METH_O, math_cos_doc},
  2170. {"cosh", math_cosh, METH_O, math_cosh_doc},
  2171. MATH_DEGREES_METHODDEF
  2172. MATH_DIST_METHODDEF
  2173. {"erf", math_erf, METH_O, math_erf_doc},
  2174. {"erfc", math_erfc, METH_O, math_erfc_doc},
  2175. {"exp", math_exp, METH_O, math_exp_doc},
  2176. {"expm1", math_expm1, METH_O, math_expm1_doc},
  2177. {"fabs", math_fabs, METH_O, math_fabs_doc},
  2178. MATH_FACTORIAL_METHODDEF
  2179. MATH_FLOOR_METHODDEF
  2180. MATH_FMOD_METHODDEF
  2181. MATH_FREXP_METHODDEF
  2182. MATH_FSUM_METHODDEF
  2183. {"gamma", math_gamma, METH_O, math_gamma_doc},
  2184. MATH_GCD_METHODDEF
  2185. {"hypot", (PyCFunction)(void(*)(void))math_hypot, METH_FASTCALL, math_hypot_doc},
  2186. MATH_ISCLOSE_METHODDEF
  2187. MATH_ISFINITE_METHODDEF
  2188. MATH_ISINF_METHODDEF
  2189. MATH_ISNAN_METHODDEF
  2190. MATH_LDEXP_METHODDEF
  2191. {"lgamma", math_lgamma, METH_O, math_lgamma_doc},
  2192. MATH_LOG_METHODDEF
  2193. {"log1p", math_log1p, METH_O, math_log1p_doc},
  2194. MATH_LOG10_METHODDEF
  2195. MATH_LOG2_METHODDEF
  2196. MATH_MODF_METHODDEF
  2197. MATH_POW_METHODDEF
  2198. MATH_RADIANS_METHODDEF
  2199. {"remainder", (PyCFunction)(void(*)(void))math_remainder, METH_FASTCALL, math_remainder_doc},
  2200. {"sin", math_sin, METH_O, math_sin_doc},
  2201. {"sinh", math_sinh, METH_O, math_sinh_doc},
  2202. {"sqrt", math_sqrt, METH_O, math_sqrt_doc},
  2203. {"tan", math_tan, METH_O, math_tan_doc},
  2204. {"tanh", math_tanh, METH_O, math_tanh_doc},
  2205. MATH_TRUNC_METHODDEF
  2206. {NULL, NULL} /* sentinel */
  2207. };
  2208. PyDoc_STRVAR(module_doc,
  2209. "This module is always available. It provides access to the\n"
  2210. "mathematical functions defined by the C standard.");
  2211. static struct PyModuleDef mathmodule = {
  2212. PyModuleDef_HEAD_INIT,
  2213. "math",
  2214. module_doc,
  2215. -1,
  2216. math_methods,
  2217. NULL,
  2218. NULL,
  2219. NULL,
  2220. NULL
  2221. };
  2222. PyMODINIT_FUNC
  2223. PyInit_math(void)
  2224. {
  2225. PyObject *m;
  2226. m = PyModule_Create(&mathmodule);
  2227. if (m == NULL)
  2228. goto finally;
  2229. PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
  2230. PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
  2231. PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
  2232. PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
  2233. #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
  2234. PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));
  2235. #endif
  2236. finally:
  2237. return m;
  2238. }