Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get minimum and maximum value of each type in elixir

Tags:

elixir

How to get minimum and maximum value of each type in elixir? for example an integer, float and maximum possible length of a string.

I know that in C it's defined in limits.h as INT_MIN, INT_MAX and so on. Where the documentation about the limit of those types in elixir?

like image 659
Kokizzu Avatar asked Jan 22 '15 16:01

Kokizzu


1 Answers

Elixir (Erlang actually) uses bignum arithmetic, which is a kind of arithmentic used in computer science where (quoting Wikipedia)

calculations are performed on numbers whose digits of precision are limited only by the available memory of the host system

There's a page in the Erlang docs which talks about the limits of the Erlang VM (e.g., atoms can have a maximum of 255 characters); as you can see if you give a look at that page, integers limits aren't even mentioned.

Integers in Erlang/Elixir are only limited by the memory available on the system, so there's virtually no limit on how large they can be.

For binaries (strings), I will just quote what the page I linked above says:

In the 32-bit implementation of Erlang, 536870911 bytes is the largest binary that can be constructed or matched using the bit syntax. (In the 64-bit implementation, the maximum size is 2305843009213693951 bytes.) If the limit is exceeded, bit syntax construction will fail with a system_limit exception, while any attempt to match a binary that is too large will fail. This limit is enforced starting with the R11B-4 release; in earlier releases, operations on too large binaries would in general either fail or give incorrect results. In future releases of Erlang/OTP, other operations that create binaries (such as list_to_binary/1) will probably also enforce the same limit.

like image 84
whatyouhide Avatar answered Oct 03 '22 21:10

whatyouhide