changeset: 102667:68f2d6098be1 parent: 102664:5ca8790f1161 user: Guido van Rossum date: Mon Aug 15 09:12:52 2016 -0700 files: Doc/library/cmath.rst Doc/library/math.rst Include/pymath.h Lib/test/test_math.py Misc/NEWS Modules/cmathmodule.c Modules/mathmodule.c description: Issue #12345: Add mathemathcal constant tau to math and cmath. Patch by Lisa Roach. See also PEP 628. diff -r 5ca8790f1161 -r 68f2d6098be1 Doc/library/cmath.rst --- a/Doc/library/cmath.rst Mon Aug 15 03:23:23 2016 -0400 +++ b/Doc/library/cmath.rst Mon Aug 15 09:12:52 2016 -0700 @@ -253,6 +253,10 @@ 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 @@ 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. - - diff -r 5ca8790f1161 -r 68f2d6098be1 Doc/library/math.rst --- a/Doc/library/math.rst Mon Aug 15 03:23:23 2016 -0400 +++ b/Doc/library/math.rst Mon Aug 15 09:12:52 2016 -0700 @@ -426,6 +426,13 @@ 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 `_, and start celebrating + `Tau day `_ by eating twice as much pie! .. data:: inf diff -r 5ca8790f1161 -r 68f2d6098be1 Include/pymath.h --- a/Include/pymath.h Mon Aug 15 03:23:23 2016 -0400 +++ b/Include/pymath.h Mon Aug 15 09:12:52 2016 -0700 @@ -55,6 +55,12 @@ #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 diff -r 5ca8790f1161 -r 68f2d6098be1 Lib/test/test_math.py --- a/Lib/test/test_math.py Mon Aug 15 03:23:23 2016 -0400 +++ b/Lib/test/test_math.py Mon Aug 15 09:12:52 2016 -0700 @@ -196,6 +196,7 @@ 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) diff -r 5ca8790f1161 -r 68f2d6098be1 Misc/NEWS --- a/Misc/NEWS Mon Aug 15 03:23:23 2016 -0400 +++ b/Misc/NEWS Mon Aug 15 09:12:52 2016 -0700 @@ -57,6 +57,9 @@ 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 diff -r 5ca8790f1161 -r 68f2d6098be1 Modules/cmathmodule.c --- a/Modules/cmathmodule.c Mon Aug 15 03:23:23 2016 -0400 +++ b/Modules/cmathmodule.c Mon Aug 15 09:12:52 2016 -0700 @@ -1239,6 +1239,7 @@ 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 */ diff -r 5ca8790f1161 -r 68f2d6098be1 Modules/mathmodule.c --- a/Modules/mathmodule.c Mon Aug 15 03:23:23 2016 -0400 +++ b/Modules/mathmodule.c Mon Aug 15 09:12:52 2016 -0700 @@ -2144,6 +2144,7 @@ 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()));