Almkvist-Giullera formula for pi: Difference between revisions
m
domain check for ilog()
m (domain check for ilog()) |
|||
Line 166:
=={{header|Erlang}}==
This version uses integer math only (does not resort to a rational number package) Since the denominator is always a power of 10, it's possible to just keep track of the log of the denominator and scale the numerator accordingly; to keep track of the accuracy we
However, Erlang does not have much in the way of calculating with large integers beyond basic arithmetic, so this version implements integer powers, logs, square roots, as well as the factorial function.
Line 193:
% integer logarithm, based on Zeckendorf representations of integers.
% https://www.keithschwarz.com/interesting/code/?dir=zeckendorf-logarithm
% we need this, since the exponents get larger than IEEE-754 double can handle.
Line 198 ⟶ 199:
logprev({A, B, S, T}) -> {B-A, A, T div S, S}.
ilog(A, B) when (A =< 0) or (B < 2) -> ilog_domain_error;
ilog(A, B) ->
UBound = bracket(A, {0, 1, 1, B}),
|