Skip to content

Commit 1933e5f

Browse files
committed
Add math.exp2
1 parent f51b130 commit 1933e5f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Lib/test/test_math.py

+11
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ def testExp(self):
485485
self.assertTrue(math.isnan(math.exp(NAN)))
486486
self.assertRaises(OverflowError, math.exp, 1000000)
487487

488+
def testExp2(self):
489+
self.assertRaises(TypeError, math.exp2)
490+
self.ftest('exp2(-1)', math.exp2(-1), 0.5)
491+
self.ftest('exp2(0)', math.exp2(0), 1)
492+
self.ftest('exp2(1)', math.exp2(1), 2)
493+
self.ftest('exp2(2.3)', math.exp2(2.3), 4.924577653379665)
494+
self.assertEqual(math.exp2(INF), INF)
495+
self.assertEqual(math.exp2(NINF), 0.)
496+
self.assertTrue(math.isnan(math.exp2(NAN)))
497+
self.assertRaises(OverflowError, math.exp2, 1000000)
498+
488499
def testFabs(self):
489500
self.assertRaises(TypeError, math.fabs)
490501
self.ftest('fabs(-1)', math.fabs(-1), 1)

stdlib/src/math.rs

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ mod math {
120120
call_math_func!(exp, x, vm)
121121
}
122122

123+
#[pyfunction]
124+
fn exp2(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {
125+
call_math_func!(exp2, x, vm)
126+
}
127+
123128
#[pyfunction]
124129
fn expm1(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {
125130
call_math_func!(exp_m1, x, vm)

0 commit comments

Comments
 (0)