diff --git a/pymbolic/algorithm.py b/pymbolic/algorithm.py index 15ba66081aef178c89a4010f22550f09984552ed..5c3dee32f6f375c5af09c6827f208e310702cbc9 100644 --- a/pymbolic/algorithm.py +++ b/pymbolic/algorithm.py @@ -50,6 +50,8 @@ def integer_power(x, n, one=1): x = x * x n //= 2 + return aux + # }}} diff --git a/test/test_pymbolic.py b/test/test_pymbolic.py index 2cb1be296cf4f945abc4a6dcf39ed8601ad44a7d..ca83b7225f4abbd3be973dc47fd930390eb7b197 100644 --- a/test/test_pymbolic.py +++ b/test/test_pymbolic.py @@ -33,6 +33,18 @@ except NameError: from functools import reduce +def test_integer_power(): + from pymbolic.algorithm import integer_power + + for base, expn in [ + (17, 5), + (17, 2**10), + (13, 20), + (13, 1343), + ]: + assert base**expn == integer_power(base, expn) + + def test_expand(): from pymbolic import var, expand