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

别来无恙 提交于 2019-12-21 07:57:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28093580/how-to-get-minimum-and-maximum-value-of-each-type-in-elixir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!