libbaltcalc

Documentation.

What is libbaltcalc?

libbaltcalc is a balanced ternary integer mathematics library for the python programming language.

Links:

SBTCVM project. A balanced ternary virtual machine
libbaltcalc on GitHub
LepVulpes' Page on balanced ternary

btint class

syntax:

int1=btint("+-")
int2=btint(2)
int3=btint(int2)

the btint class provides support for python's builtin integer mathematics methods, and some others

methods

invert() (returns the balanced ternary inversion. i.e. -+0- becomes +-0+)
dec()    (explicitly returns a normal python integer)
bt()     (explicitly returns balanced ternary integer in string form.)

supported python methods and notes about implementation of them.

__str__ (returns balanced ternary integer in string form.
__int__ (returns a normal python integer)

(these mathematics methods return btint instances.)
__add__

__sub__

__truediv__, __div__, __floordiv__ (limited to integers only as floating point operations are not yet supported)

__mul__

__abs__

__neg__
__pos__
__invert__ ( returns the balanced ternary inversion. i.e. -+0- becomes +-0+)


functions:

(mpi, mni, and mcv expect and return decimal integers)

mpi(tritlen) returns the max positive integer of a length of trits

mni(tritlen) returns the max negative integer of a length of trits

mcv(tritlen) returns the max combinations value of a length of trits

Low Level Balanced ternary integer string operations

BTTODEC and DECTOBT are the library's core conversion operations.

BTTODEC(btintstring)                 returns value of a balance ternary integer (in string form) as a decimal integer

DECTOBT(integer)                     returns a balance ternary integer (in string form) equal to integer argument

It is recommended to usually use the high level btint class for such operations.

btadd(btintstring, btintstring)      addition

btmul(btintstring, btintstring)      multiplication

btsub(btintstring, btintstring)      subtraction

btdiv(btintstring, btintstring)      integer division.

btdivcpu(btintstring, btintstring)   (used by SBTCVM project. returns "ZDIV" on zero division

BTINVERT(btintstring)                (returns the inversion of a balanced ternary integer string)