Bignum
This module provides function and classes to operate on arbitrary precision integers. It is based on the very high performance library TomMath slightly modified to be compatible with Zerynth memory manager.
The Bignum class
class BigNum
BigNum(val=0)
This class represents a big integer number with arbitrary precision. A big number instance can be initialized with a value val. val can be a standard integer or a string representing the number. The string is accepted if it is in base 16 prefixed with '0x' or in base 10. Signed number are accepted. At the moment, bytearray or bytes representation are not supported.
BigNum instances are compatible with streams and, if printed, are automatically converted to the base 10 string format.
BigNum instances are easy to use: ::
from bignum import bignum as bg
import streams
streams.serial()
big = bg.BigNum("1234567890987654321")
one = bg.BigNum(1)
while True:
print(big)
big.iadd(one)
sleep(1000)
method add
add(b)
Return a new big number instance equal to the addition of the current instance and b.
method iadd
iadd(b)
Add to the current instance the big number b. Return None
method sub
sub(b)
Return a new big number instance equal to the difference of the current instance and b.
method isub
isub(b)
Subtracts to the current instance the big number b. Return None
method mul
mul(b)
Return a new big number instance equal to the multiplication of the current instance and b.
method imul
imul(,b)
Multiply the current instance for the big number b. Return None
method div
div(b)
Return a new big number instance equal to the division of the current instance by b.
method idiv
idiv(b)
Divides the current instance for the big number b. Return None
method mod
mod(b)
Return a new big number instance equal to the remainder of the division of the current instance by b.
method imod
imod(b)
Set the current instance to the remainder of the division by b. Return None
method divmod
divmod(b)
Return a tuple (q,r) of new big number instances representing the quotient q and the remainder r of the division of the current instance by b.