From eeae7b1ce54835e4f63b4c7482040f8cd33da2f4 Mon Sep 17 00:00:00 2001 From: tareknaser360 Date: Wed, 1 Mar 2023 11:55:58 +0200 Subject: [PATCH] added exp2 function --- integration_tests/test_math.py | 8 +++++++- src/runtime/math.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_math.py b/integration_tests/test_math.py index 315b4efb8e..3e2a071564 100644 --- a/integration_tests/test_math.py +++ b/integration_tests/test_math.py @@ -1,4 +1,4 @@ -from math import (factorial, isqrt, perm, comb, degrees, radians, exp, pow, +from math import (factorial, isqrt, perm, comb, degrees, radians, exp, exp2, pow, ldexp, fabs, gcd, lcm, floor, ceil, remainder, expm1, fmod, log1p, trunc, modf, fsum, prod, dist) import math @@ -60,6 +60,11 @@ def test_exp(): i = exp(2.34) assert abs(i - 10.381236562731843) < eps +def test_exp2(): + i: f64 + i = exp2(2.34) + assert abs(i - 5.06302637588112) < eps + def test_pow(): eps: f64 @@ -262,6 +267,7 @@ def check(): test_degrees() test_radians() test_exp() + test_exp2() test_pow() test_fabs() test_ldexp() diff --git a/src/runtime/math.py b/src/runtime/math.py index 203582c565..f248de3b5f 100644 --- a/src/runtime/math.py +++ b/src/runtime/math.py @@ -466,6 +466,13 @@ def exp(x: f64) -> f64: return e**x +def exp2(x: f64) -> f64: + """ + Return 2 raised to the power `x`. + """ + return 2**x + + def mod(a: i32, b: i32) -> i32: """ Returns a%b