May 22, 2008
Numeric Limitations in Erlang
The debugging process for the erlang distribution code continues. While debugging the binomial distribution last night I wrote a naive factorial calculator the code for which is common.
%factorial of N
fact_helper(0, Product) ->
fact_helper(1, Product) ->
fact_helper(N, Product) ->
fact_helper(N - 1, Product * N).
Out of curiosity I started plugging in large numbers. The largest I have tried is 50,000! It took about 1.5 seconds to calculate and the result is much to large to post here. In fact, I was going to post it here but the number is too large to fit in the clipboard on my machine. Even if the sequence of digits was divided into 6 segments the segments still don’t fit in the clipboard.
This seems to indicate that for integer addition, subtraction, and multiplication the upper numerical bound is limited only by your hardware.
Division is different. It appears to use standard floating point type algorithms. Floating point numbers appear to have a limit similar to other languages and causes an error if the numbers are too large.
yeilds 20 as expected.
** exception error: bad argument in an arithmetic expression
in operator '/'/2
throws a bad argument exception for the division operator. Floating point numbers therefor must have a maximum size that is less than 199!
An amazing language.