Skip to content

Commit 0a891d7

Browse files
author
Guido van Rossum
committed
Issue #12345: Add mathemathcal constant tau to math and cmath.
Patch by Lisa Roach. See also PEP 628.
1 parent 6349612 commit 0a891d7

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

Doc/library/cmath.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ Constants
253253

254254
The mathematical constant *e*, as a float.
255255

256+
.. data:: tau
257+
258+
The mathematical constant *τ*, as a float.
259+
256260
.. index:: module: math
257261

258262
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:
276280
Kahan, W: Branch cuts for complex elementary functions; or, Much ado about
277281
nothing's sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art
278282
in numerical analysis. Clarendon Press (1987) pp165-211.
279-
280-

Doc/library/math.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ Constants
426426

427427
The mathematical constant e = 2.718281..., to available precision.
428428

429+
.. data:: tau
430+
431+
The mathematical constant τ = 6.283185..., to available precision.
432+
Tau is a circle constant equal to 2π, the ratio of a circle's circumference to
433+
its radius. To learn more about Tau, check out Vi Hart's video `Pi is (still)
434+
Wrong <https://www.youtube.com/watch?v=jG7vhMMXagQ>`_, and start celebrating
435+
`Tau day <http://tauday.com/>`_ by eating twice as much pie!
429436

430437
.. data:: inf
431438

Include/pymath.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ extern double pow(double, double);
5555
#define Py_MATH_E 2.7182818284590452354
5656
#endif
5757

58+
/* Tau (2pi) to 40 digits, taken from tauday.com/tau-digits. */
59+
#ifndef Py_MATH_TAU
60+
#define Py_MATH_TAU 6.2831853071795864769252867665590057683943L
61+
#endif
62+
63+
5864
/* On x86, Py_FORCE_DOUBLE forces a floating-point number out of an x87 FPU
5965
register and into a 64-bit memory location, rounding from extended
6066
precision to double precision in the process. On other platforms it does

Lib/test/test_math.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def ftest(self, name, value, expected):
196196
def testConstants(self):
197197
self.ftest('pi', math.pi, 3.1415926)
198198
self.ftest('e', math.e, 2.7182818)
199+
self.assertEqual(math.tau, 2*math.pi)
199200

200201
def testAcos(self):
201202
self.assertRaises(TypeError, math.acos)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Core and Builtins
5757
Library
5858
-------
5959

60+
- Issue #12345: Add mathemathcal constant tau to math and cmath. See also
61+
PEP 628.
62+
6063
- Issue #26823: traceback.StackSummary.format now abbreviates large sections of
6164
repeated lines as "[Previous line repeated {count} more times]" (this change
6265
then further affects other traceback display operations in the module). Patch

Modules/cmathmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ PyInit_cmath(void)
12391239
PyModule_AddObject(m, "pi",
12401240
PyFloat_FromDouble(Py_MATH_PI));
12411241
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
1242+
PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
12421243

12431244
/* initialize special value tables */
12441245

Modules/mathmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,7 @@ PyInit_math(void)
21442144

21452145
PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
21462146
PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
2147+
PyModule_AddObject(m, "tau", PyFloat_FromDouble(Py_MATH_TAU)); /* 2pi */
21472148
PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
21482149
#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
21492150
PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));

0 commit comments

Comments
 (0)