From bb3027ea528d923be0a68c38ac231e469125cb8d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 11 Jun 2013 18:45:05 -0400 Subject: [PATCH] Fix, test integer power algorithm --- pymbolic/algorithm.py | 2 ++ test/test_pymbolic.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pymbolic/algorithm.py b/pymbolic/algorithm.py index 15ba660..5c3dee3 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 2cb1be2..ca83b72 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 -- GitLab