[erlang-questions] Truncation packing Integer into binary: bug or feature?

Edwin Fine erlang-questions_efine@REDACTED
Fri Aug 22 00:12:34 CEST 2008

 If one packs a large Erlang integer into a binary, and the binary
representation of that integer is too large for the number of bytes
specified, Erlang silently truncates it (see code below).

Is this a bug or a feature? I know that in C, integers overflow silently. I
would have thought Erlang would raise a badarg error or something. Or would
it negatively impact performance to check for overflow? Is there a place in
the docs I did not find that addresses this? I have searched the Erlang
documentation, Google and the Erlang mailing list archives for clues and
found nothing so far.

1> N=314159265358979323846.
2> B = <<N:64/integer>>.
3> <<N1:64/integer>> = B.
4> N1.

I'm using R12B-3 on x86_64 Ubuntu.

Edwin Fine
For every expert there is an equal and opposite expert - Arthur C. Clarke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080821/84e6442c/attachment.htm>

More information about the erlang-questions mailing list