| 1 | """num.py - math functions"""
|
| 2 | from __future__ import print_function
|
| 3 |
|
| 4 | from _devbuild.gen.value_asdl import value
|
| 5 | from mycpp import mops
|
| 6 |
|
| 7 |
|
| 8 | def ToBig(i):
|
| 9 | # type: (int) -> value.Int
|
| 10 | return value.Int(mops.IntWiden(i))
|
| 11 |
|
| 12 |
|
| 13 | def 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
|