Bignum¶
This module provides function and classes to operate on arbitrary precision integers. It is based on the very perfomant library TomMath slightly modified to be compatible with Zerynth memory manager.
The Bignum class¶

class
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)

add
(b)¶ Return a new big number instance equal to the addition of the current instance and b.

iadd
(b)¶ Add to the current instance the big number b. Return
None

sub
(b)¶ Return a new big number instance equal to the difference of the current instance and b.

isub
(b)¶ Subtracts to the current instance the big number b. Return
None

mul
(b)¶ Return a new big number instance equal to the multiplication of the current instance and b.

imul
(b)¶ Multiply the current instance for the big number b. Return
None

div
(b)¶ Return a new big number instance equal to the division of the current instance by b.

idiv
(b)¶ Divides the current instance for the big number b. Return
None

mod
(b)¶ Return a new big number instance equal to the remainder of the division of the current instance by b.

imod
(b)¶ Set the current instance to the remainder of the division by b. Return
None

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.

to_base
(base)¶ Return a string representation of the big number in base base. Allowed values for base are in the range 2..64.