]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12345: Add mathemathcal constant tau to math and cmath.
authorGuido van Rossum <guido@dropbox.com>
Mon, 15 Aug 2016 16:12:52 +0000 (09:12 -0700)
committerGuido van Rossum <guido@dropbox.com>
Mon, 15 Aug 2016 16:12:52 +0000 (09:12 -0700)
Patch by Lisa Roach. See also PEP 628.

Doc/library/cmath.rst
Doc/library/math.rst
Include/pymath.h
Lib/test/test_math.py
Misc/NEWS
Modules/cmathmodule.c
Modules/mathmodule.c

index 62ddb6bc4877362f66f81c65588ae3e8d05eedaf..f04f8d01955804cee26ff39b33c3670724e30220 100644 (file)
@@ -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.
-
-
index 3fdea18cfd94d2f096b6428b69af306c2f2e380d..32e1352bfff0230f32b8dc5d764f46ddd031c6af 100644 (file)
@@ -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
 
index ed76053b816229f590e5fdb52b5dc43b0cce7e92..894362e698136f82b6d11472b7eae4ad869d5d00 100644 (file)
@@ -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
index 605adb527abb3f3dca24788f2dd416834769fb09..48e8007bc71a54934a12413fbb637e7044c0385b 100644 (file)
@@ -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)
index eabbf8c49db670daae497ecd4b96712a1cbbe2ba..ec86a53d651a8d56f9f46e2ca8fdc1010f418130 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
index cba42a7257a08378355ba20abe6b3dd1929bd738..0e7d4db96d4857f155d9c43ca09e263ff0b98a1c 100644 (file)
@@ -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 */
 
index cf049010eaeb05f53b72c3707b5cb21639e3c375..43aa229eb714248247217dc1385dd62d18b3b7d2 100644 (file)
@@ -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()));