[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.
*314159265358979323846*
2> B = <<N:64/integer>>.
<<7,213,235,91,91,164,215,198>>
3> <<N1:64/integer>> = B.
<<7,213,235,91,91,164,215,198>>
4> N1.
*564616105916946374*
5>

I'm using R12B-3 on x86_64 Ubuntu.

Regards,
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