How does Erlang store large numbers?

I dealt with the factorial module as follows:

-module(factorial). -export([factorial/1]). factorial(0) -> 1; factorial(Val)-> Val * factorial(Val-1). 

If I run:

 1> c(factorial). {ok,factorial} 2> factorial:factorial(100). 

I get: 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000000000

How does Erlang hold such large numbers so easily? On erlang.org, when he talks about types of numbers, he simply claims that they contain either integers or float. Should it be some kind of dynamic integer that adjusts the byte size if necessary?

I think this is very cool, I just don’t know how to do it.

+5
source share
1 answer

This is a common feature of many functional programming languages, called arbitrary precision arithmetic .

Note that in Erlang arbitrary precision is available o for integers, not floats .

+4
source

Source: https://habr.com/ru/post/1247245/


All Articles