We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c1f93f0 commit 6266e4aCopy full SHA for 6266e4a
Doc/library/math.rst
@@ -356,6 +356,13 @@ Power and logarithmic functions
356
or ``pow(math.e, x)``.
357
358
359
+.. function:: exp2(x)
360
+
361
+ Return *2* raised to the power *x*.
362
363
+ .. versionadded:: 3.11
364
365
366
.. function:: expm1(x)
367
368
Return *e* raised to the power *x*, minus 1. Here *e* is the base of natural
Doc/whatsnew/3.11.rst
@@ -203,6 +203,8 @@ fractions
203
204
math
205
----
206
+* Add :func:`math.exp2`: return 2 raised to the power of x.
207
+ (Contributed by Gideon Mitchell in :issue:`45917`.)
208
209
* Add :func:`math.cbrt`: return the cube root of x.
210
(Contributed by Ajith Ramachandran in :issue:`44357`.)
Lib/test/test_math.py
@@ -501,6 +501,17 @@ def testExp(self):
501
self.assertTrue(math.isnan(math.exp(NAN)))
502
self.assertRaises(OverflowError, math.exp, 1000000)
503
504
+ def testExp2(self):
505
+ self.assertRaises(TypeError, math.exp2)
506
+ self.ftest('exp2(-1)', math.exp2(-1), 0.5)
507
+ self.ftest('exp2(0)', math.exp2(0), 1)
508
+ self.ftest('exp2(1)', math.exp2(1), 2)
509
+ self.ftest('exp2(2.3)', math.exp2(2.3), 4.924577653379665)
510
+ self.assertEqual(math.exp2(INF), INF)
511
+ self.assertEqual(math.exp2(NINF), 0.)
512
+ self.assertTrue(math.isnan(math.exp2(NAN)))
513
+ self.assertRaises(OverflowError, math.exp2, 1000000)
514
515
def testFabs(self):
516
self.assertRaises(TypeError, math.fabs)
517
self.ftest('fabs(-1)', math.fabs(-1), 1)
Misc/ACKS
@@ -1191,6 +1191,7 @@ Julien Miotte
1191
Andrii V. Mishkovskyi
1192
Dom Mitchell
1193
Dustin J. Mitchell
1194
+Gideon Mitchell
1195
Tim Mitchell
1196
Zubin Mithra
1197
Florian Mladitsch
Misc/NEWS.d/next/Library/2021-11-28-17-24-11.bpo-45917.J5TIrd.rst
@@ -0,0 +1 @@
1
+Added :func:`math.exp2`:, which returns 2 raised to the power of x.
Modules/mathmodule.c
@@ -1248,6 +1248,9 @@ FUNC1A(erfc, m_erfc,
1248
FUNC1(exp, exp, 1,
1249
"exp($module, x, /)\n--\n\n"
1250
"Return e raised to the power of x.")
1251
+FUNC1(exp2, exp2, 1,
1252
+ "exp2($module, x, /)\n--\n\n"
1253
+ "Return 2 raised to the power of x.")
1254
FUNC1(expm1, expm1, 1,
1255
"expm1($module, x, /)\n--\n\n"
1256
"Return exp(x)-1.\n\n"
@@ -3564,6 +3567,7 @@ static PyMethodDef math_methods[] = {
3564
3567
{"erf", math_erf, METH_O, math_erf_doc},
3565
3568
{"erfc", math_erfc, METH_O, math_erfc_doc},
3566
3569
{"exp", math_exp, METH_O, math_exp_doc},
3570
+ {"exp2", math_exp2, METH_O, math_exp2_doc},
3571
{"expm1", math_expm1, METH_O, math_expm1_doc},
3572
{"fabs", math_fabs, METH_O, math_fabs_doc},
3573
MATH_FACTORIAL_METHODDEF
0 commit comments