Thursday, June 1, 2017

Balanced ternary: Overhauling libbaltcalc's aging, clunky API

new libbaltcalc 3.x series.
 while the old balance ternary integer string API is still present, its been cleaned up a bit. also a new class-based API now exists.

the btint class provides a more seamless API in python.

as an example lets add 2 and 4
old API:
>>>import libbaltcalc
>>>int1=libbaltcalc.DECTOBT(2)
>>>int2=libbaltcalc.DECTOBT(4)
>>>print libbaltcalc.btadd(int1, int2)
+-0

the new btint class can accept integers, balanced ternary integer strings, and other btint instances as an argument. not only that, but all supported mathematics operations return btint instances. and btint instances can be printed and used quite simply.

new API:
>>>import libbaltcalc
>>>from libbaltcalc import btint
>>>int1=btint(2)
>>>int2=btint(4)
>>>print int1 + int2
+-0

Now wasn't that easier?

new libbaltcalc documentation

No comments:

Post a Comment