OILS / core / num.py View on Github | oilshell.org

24 lines, 12 significant
1"""num.py - math functions"""
2from __future__ import print_function
3
4from _devbuild.gen.value_asdl import value
5from mycpp import mops
6
7
8def ToBig(i):
9 # type: (int) -> value.Int
10 return value.Int(mops.IntWiden(i))
11
12
13def Exponent(x, y):
14 # type: (mops.BigInt, mops.BigInt) -> mops.BigInt
15
16 # TODO: can we avoid this?
17 y_int = mops.BigTruncate(y)
18
19 assert y_int >= 0, 'checked by caller'
20
21 result = mops.BigInt(1)
22 for i in xrange(y_int):
23 result = mops.Mul(result, x)
24 return result