Issue #12345: Add mathemathcal constant tau to math and cmath.
Patch by Lisa Roach. See also PEP 628.
This commit is contained in:
parent
6349612a8e
commit
0a891d70de
|
@ -253,6 +253,10 @@ Constants
|
|||
|
||||
The mathematical constant *e*, as a float.
|
||||
|
||||
.. data:: tau
|
||||
|
||||
The mathematical constant *τ*, as a float.
|
||||
|
||||
.. index:: module: math
|
||||
|
||||
Note that the selection of functions is similar, but not identical, to that in
|
||||
|
@ -276,5 +280,3 @@ cuts for numerical purposes, a good reference should be the following:
|
|||
Kahan, W: Branch cuts for complex elementary functions; or, Much ado about
|
||||
nothing's sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art
|
||||
in numerical analysis. Clarendon Press (1987) pp165-211.
|
||||
|
||||
|
||||
|
|
|
@ -426,6 +426,13 @@ Constants
|
|||
|
||||
The mathematical constant e = 2.718281..., to available precision.
|
||||
|
||||
.. data:: tau
|
||||
|
||||
The mathematical constant τ = 6.283185..., to available precision.
|
||||
Tau is a circle constant equal to 2π, the ratio of a circle's circumference to
|
||||
its radius. To learn more about Tau, check out Vi Hart's video `Pi is (still)
|
||||
Wrong <https://www.youtube.com/watch?v=jG7vhMMXagQ>`_, and start celebrating
|
||||
`Tau day <http://tauday.com/>`_ by eating twice as much pie!
|
||||
|
||||
.. data:: inf
|
||||
|
||||
|
|
|
@ -55,6 +55,12 @@ extern double pow(double, double);
|
|||
#define Py_MATH_E 2.7182818284590452354
|
||||
#endif
|
||||
|
||||
/* Tau (2pi) to 40 digits, taken from tauday.com/tau-digits. */
|
||||
#ifndef Py_MATH_TAU
|
||||
#define Py_MATH_TAU 6.2831853071795864769252867665590057683943L
|
||||
#endif
|
||||
|
||||
|
||||
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
|
||||
register and into a 64-bit memory location, rounding from extended
|
||||
precision to double precision in the process. On other platforms it does
|
||||
|
|
|
@ -196,6 +196,7 @@ class MathTests(unittest.TestCase):
|
|||
def testConstants(self):
|
||||
self.ftest('pi', math.pi, 3.1415926)
|
||||
self.ftest('e', math.e, 2.7182818)
|
||||
self.assertEqual(math.tau, 2*math.pi)
|
||||
|
||||
def testAcos(self):
|
||||
self.assertRaises(TypeError, math.acos)
|
||||
|
|
|
@ -57,6 +57,9 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #12345: Add mathemathcal constant tau to math and cmath. See also
|
||||
PEP 628.
|
||||
|
||||
- Issue #26823: traceback.StackSummary.format now abbreviates large sections of
|
||||
repeated lines as "[Previous line repeated {count} more times]" (this change
|
||||
then further affects other traceback display operations in the module). Patch
|
||||
|
|
|
@ -1239,6 +1239,7 @@ PyInit_cmath(void)
|
|||
PyModule_AddObject(m, "pi",
|
||||
PyFloat_FromDouble(Py_MATH_PI));
|
||||
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
|
||||
PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
|
||||
|
||||
/* initialize special value tables */
|
||||
|
||||
|
|
|
@ -2144,6 +2144,7 @@ PyInit_math(void)
|
|||
|
||||
PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
|
||||
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
|
||||
PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
|
||||
PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
|
||||
#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
|
||||
PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));
|
||||
|
|
Loading…
Reference in New Issue