mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Merged revisions 62386-62387,62389-62393,62396,62400-62402,62407,62409-62410,62412-62414,62418-62419 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r62386 | christian.heimes | 2008-04-19 04:23:57 +0200 (Sat, 19 Apr 2008) | 2 lines Added kill, terminate and send_signal to subprocess.Popen The bits and pieces for the Windows side were already in place. The POSIX side is trivial (as usual) and uses os.kill(). ........ r62387 | georg.brandl | 2008-04-19 10:23:59 +0200 (Sat, 19 Apr 2008) | 2 lines Fix-up docs for revision 62386. ........ r62389 | georg.brandl | 2008-04-19 18:57:43 +0200 (Sat, 19 Apr 2008) | 2 lines #2369: clarify that copyfile() doesn't take a target directory. ........ r62390 | georg.brandl | 2008-04-19 18:58:28 +0200 (Sat, 19 Apr 2008) | 2 lines #2634: clarify meaning of env parameter to spawn/exec*e. ........ r62391 | georg.brandl | 2008-04-19 18:58:49 +0200 (Sat, 19 Apr 2008) | 2 lines #2633: clarify meaning of env parameter. ........ r62392 | georg.brandl | 2008-04-19 18:59:16 +0200 (Sat, 19 Apr 2008) | 2 lines #2631: clarify IMPORT_NAME semantics. ........ r62393 | georg.brandl | 2008-04-19 19:00:14 +0200 (Sat, 19 Apr 2008) | 2 lines :func: et al. should *not* include the parens. ........ r62396 | mark.dickinson | 2008-04-19 20:51:48 +0200 (Sat, 19 Apr 2008) | 5 lines Additional tests for math.pow, and extra special-case handling code in math.pow, in the hope of making all tests pass on the alpha Tru64 buildbot. ........ r62400 | mark.dickinson | 2008-04-19 21:41:52 +0200 (Sat, 19 Apr 2008) | 3 lines Additional special-case handling for math.pow. Windows/VS2008 doesn't like (-1)**(+-inf). ........ r62401 | benjamin.peterson | 2008-04-19 21:47:34 +0200 (Sat, 19 Apr 2008) | 2 lines Complete documentation for errors argument of io's open and TextIOWrapper ........ r62402 | mark.dickinson | 2008-04-19 22:31:16 +0200 (Sat, 19 Apr 2008) | 2 lines Document updates to math and cmath modules. ........ r62407 | georg.brandl | 2008-04-19 23:28:38 +0200 (Sat, 19 Apr 2008) | 2 lines Update template for newest Sphinx. ........ r62409 | mark.dickinson | 2008-04-19 23:35:35 +0200 (Sat, 19 Apr 2008) | 5 lines Correct documentation for math.pow; 0**nan is nan, not 0. (But nan**0 and 1**nan are 1.) Also fix minor typo: 'quite NaN' -> 'quiet NaN' ........ r62410 | mark.dickinson | 2008-04-19 23:49:22 +0200 (Sat, 19 Apr 2008) | 4 lines Move asinh documentation to the proper place. Remove meaningless 'in radians' from inverse hyperbolic functions. ........ r62412 | mark.dickinson | 2008-04-20 03:22:30 +0200 (Sun, 20 Apr 2008) | 5 lines Report additional diagnostic information in test_math, to help track down debian-alpha buildbot failure. ........ r62413 | mark.dickinson | 2008-04-20 03:39:24 +0200 (Sun, 20 Apr 2008) | 3 lines FreeBSD doesn't follow C99 for modf(inf); so add explicit special-value handling to math.modf code. ........ r62414 | mark.dickinson | 2008-04-20 06:13:13 +0200 (Sun, 20 Apr 2008) | 5 lines Yet more explicit special case handling to make math.pow behave on alpha Tru64. All IEEE 754 special values are now handled directly; only the finite**finite case is handled by libm. ........ r62418 | mark.dickinson | 2008-04-20 18:13:17 +0200 (Sun, 20 Apr 2008) | 7 lines Issue 2662: Initialize special value tables dynamically (i.e. when cmath module is loaded) instead of statically. This fixes compile-time problems on platforms where HUGE_VAL is an extern variable rather than a constant. Thanks Hirokazu Yamamoto for the patch. ........ r62419 | andrew.kuchling | 2008-04-20 18:54:02 +0200 (Sun, 20 Apr 2008) | 1 line Move description of math module changes; various edits to description of cmath changes ........
This commit is contained in:
parent
58f9e4f347
commit
a342c013fc
15 changed files with 585 additions and 210 deletions
|
|
@ -414,6 +414,15 @@ math_modf(PyObject *self, PyObject *arg)
|
|||
double y, x = PyFloat_AsDouble(arg);
|
||||
if (x == -1.0 && PyErr_Occurred())
|
||||
return NULL;
|
||||
/* some platforms don't do the right thing for NaNs and
|
||||
infinities, so we take care of special cases directly. */
|
||||
if (!Py_IS_FINITE(x)) {
|
||||
if (Py_IS_INFINITY(x))
|
||||
return Py_BuildValue("(dd)", copysign(0., x), x);
|
||||
else if (Py_IS_NAN(x))
|
||||
return Py_BuildValue("(dd)", x, x);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
PyFPE_START_PROTECT("in math_modf", return 0);
|
||||
x = modf(x, &y);
|
||||
|
|
@ -586,6 +595,7 @@ math_pow(PyObject *self, PyObject *args)
|
|||
{
|
||||
PyObject *ox, *oy;
|
||||
double r, x, y;
|
||||
int odd_y;
|
||||
|
||||
if (! PyArg_UnpackTuple(args, "pow", 2, 2, &ox, &oy))
|
||||
return NULL;
|
||||
|
|
@ -593,37 +603,62 @@ math_pow(PyObject *self, PyObject *args)
|
|||
y = PyFloat_AsDouble(oy);
|
||||
if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
|
||||
return NULL;
|
||||
/* 1**x and x**0 return 1., even if x is a NaN or infinity. */
|
||||
if (x == 1.0 || y == 0.0)
|
||||
return PyFloat_FromDouble(1.);
|
||||
errno = 0;
|
||||
PyFPE_START_PROTECT("in math_pow", return 0);
|
||||
r = pow(x, y);
|
||||
PyFPE_END_PROTECT(r);
|
||||
if (Py_IS_NAN(r)) {
|
||||
if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
|
||||
errno = EDOM;
|
||||
else
|
||||
errno = 0;
|
||||
|
||||
/* deal directly with IEEE specials, to cope with problems on various
|
||||
platforms whose semantics don't exactly match C99 */
|
||||
if (!Py_IS_FINITE(x) || !Py_IS_FINITE(y)) {
|
||||
errno = 0;
|
||||
if (Py_IS_NAN(x))
|
||||
r = y == 0. ? 1. : x; /* NaN**0 = 1 */
|
||||
else if (Py_IS_NAN(y))
|
||||
r = x == 1. ? 1. : y; /* 1**NaN = 1 */
|
||||
else if (Py_IS_INFINITY(x)) {
|
||||
odd_y = Py_IS_FINITE(y) && fmod(fabs(y), 2.0) == 1.0;
|
||||
if (y > 0.)
|
||||
r = odd_y ? x : fabs(x);
|
||||
else if (y == 0.)
|
||||
r = 1.;
|
||||
else /* y < 0. */
|
||||
r = odd_y ? copysign(0., x) : 0.;
|
||||
}
|
||||
else if (Py_IS_INFINITY(y)) {
|
||||
if (fabs(x) == 1.0)
|
||||
r = 1.;
|
||||
else if (y > 0. && fabs(x) > 1.0)
|
||||
r = y;
|
||||
else if (y < 0. && fabs(x) < 1.0) {
|
||||
r = -y; /* result is +inf */
|
||||
if (x == 0.) /* 0**-inf: divide-by-zero */
|
||||
errno = EDOM;
|
||||
}
|
||||
else
|
||||
r = 0.;
|
||||
}
|
||||
}
|
||||
/* an infinite result arises either from:
|
||||
|
||||
(A) (+/-0.)**negative,
|
||||
(B) overflow of x**y with both x and y finite (and x nonzero)
|
||||
(C) (+/-inf)**positive, or
|
||||
(D) x**inf with |x| > 1, or x**-inf with |x| < 1.
|
||||
|
||||
In case (A) we want ValueError to be raised. In case (B)
|
||||
OverflowError should be raised. In cases (C) and (D) the infinite
|
||||
result should be returned.
|
||||
*/
|
||||
else if (Py_IS_INFINITY(r)) {
|
||||
if (x == 0.)
|
||||
errno = EDOM;
|
||||
else if (Py_IS_FINITE(x) && Py_IS_FINITE(y))
|
||||
errno = ERANGE;
|
||||
else
|
||||
errno = 0;
|
||||
else {
|
||||
/* let libm handle finite**finite */
|
||||
errno = 0;
|
||||
PyFPE_START_PROTECT("in math_pow", return 0);
|
||||
r = pow(x, y);
|
||||
PyFPE_END_PROTECT(r);
|
||||
/* a NaN result should arise only from (-ve)**(finite
|
||||
non-integer); in this case we want to raise ValueError. */
|
||||
if (!Py_IS_FINITE(r)) {
|
||||
if (Py_IS_NAN(r)) {
|
||||
errno = EDOM;
|
||||
}
|
||||
/*
|
||||
an infinite result here arises either from:
|
||||
(A) (+/-0.)**negative (-> divide-by-zero)
|
||||
(B) overflow of x**y with x and y finite
|
||||
*/
|
||||
else if (Py_IS_INFINITY(r)) {
|
||||
if (x == 0.)
|
||||
errno = EDOM;
|
||||
else
|
||||
errno = ERANGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errno && is_error(r))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue