bigatom

arbitrary precision arithmetic, by Carlos Gómez Andreu (cargoan)

Incluled in the distribution as builtins\bigatom.e (not an autoinclude).

I (Pete Lomax) have translated the comments as best I can, and renamed the overrides log/exp/sqrt as b_a_log/b_a_exp/b_a_sqrt.
(Phix does not allow and in fact has recently been modified to expressly prohibit any builtin overides.)
Be advised that internally this uses simple digit-by-digit mechanisms and is not a high performance implementation.
(If it is possible that instead of digits 0..9 it used "digits" 0..999,999,999 then it might be ten times faster... Maybe...)

Once you understand how to create and display bigatoms, the rest is all pretty straightforward.

bigatom - the bigatom type
bigatom ba = ba_new(object x) - create a bigatom instance value
sequence prev = ba_scale(object decs=-1, integer mode=-1) - set library precision and/or mode
string s = ba_sprintf(sequence fmt, bigatom N) - get formatted string (%B) representation
ba_printf(integer file, sequence fmt, bigatom N) - print formatted sting (%B) representation
string s = ba_sprint(bigatom N) - get standard string representation
ba_print(integer file, bigatom N) - print standard string representation
integer i = ba_scale_of(bigatom N) -- the number of decimals before the decimal point, eg ba_scale_of(ba_new(123.456)) is 3
integer i = ba_compare(bigatom A, bigatom B) -- -1/0/1 (A<B/A=B/A>B) as per compare()
bigatom ba = ba_add(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_sub(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_multiply(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_idivide(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_divide(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_remainder(object A, object B) -- A,B can be atom/string/bigatom
bigatom ba = ba_round(object N, object B) -- rounding function
bigatom ba = ba_abs(bigatom N) - absolute (unsigned) value
bigatom ba = ba_trunc(bigatom N) - integer part of a bigatom
bigatom ba = ba_frac(bigatom N) - fractional part of a bigatom
bigatom ba = ba_floor(bigatom N) - integer equal to or immediately less
bigatom ba = ba_ceil(bigatom N) - integer equal to or immediately greater
atom a = b_a_log(atom x) -- adapted from bigfixedmath.e, apparently better than log()
atom a = logb(atom x, atom base=10)
atom a = b_a_exp(atom x) -- adapted from library bc, apparently better than exp()
atom a = b_a_sqrt(atom x) -- apparently better than sqrt()
bigatom ba = ba_log(object x, integer bRound=0) -- x can be atom/string/bigatom
bigatom ba = ba_exp(object x, integer bRound=0) -- x can be atom/string/bigatom
bigatom ba = ba_power(object x, object n, integer bRound=0) -- x,n can be atom/string/bigatom (x^n)
bigatom ba = ba_sqrt(object x, integer bRound=0) -- x can be atom/string/bigatom
bigatom ba = ba_root(object x, object n, integer bRound=0) -- x,n can be atom/string/bigatom (x^(1/n))
bigatom ba = ba_log10(object x, integer bRound=0) -- x can be atom/string/bigatom
bigatom ba = ba_logb(object x, object base=10, integer bRound=0) -- x,base can be atom/string/bigatom
atom a = bigatom_to_atom(bigatom N) -- an atom with approximately the value of a bigatom
object x = ba_euler(integer decs, integer o=0) -- e to decs places, as string(o=0) or bignum