bignum support in ei?

Kent Boortz <>
Thu Jun 12 04:51:54 CEST 2003


Vance Shipley <> writes:
> On Thu, Jun 12, 2003 at 01:35:23AM +0200, Kent Boortz wrote:
> }  
> }  You mean an Erlang integer that don't fit in a C long or unsigned long?
> }  No, there is no way to decode this in the current version of ei.
> 
> Actually I was trying to send 16#ffffffff which is 32 bits no?

As documented in

  $ERL_TOP/erts/emulator/internal_doc/erl_ext_dist.txt

the 32 bit integer INTEGER_EXT in the external format is signed. So
the largest erlang integer it can hold is 16#7fffffff.

> It would appear that if the upper nibble of a 32 bit integer is not zero
> it becomes an ERL_SMALL_BIG_EXT:
> 
> }  > 16#07ffffff       134217727                          ERL_INTEGER_EXT
> }  > 16#08ffffff       #integer(2) = {65535,2303}         ERL_SMALL_BIG_EXT
> ...
> }  > Seems like a strange place to make the last break but anyway.
> }  
> }  What do you mean? What break and why is it strange?
> 
> Seems strange to me.  Why can I send this 32 bit value:
> 
> 	0000 1111 1111 1111 1111 1111 1111 1111
> 
> but not this one (without becoming a bignum):
> 
> 	0001 1111 1111 1111 1111 1111 1111 1111

You are right, this is a bit strange. It comes from how integers are
represented in the emulator. The external format doesn't specify that
an integer has to be packed into the smallest possible container in
the external format but I think both the Erlang encode functions and
the ei encode functions should do that. The decoders have to be more
tolerant.

Note that you can still use ei_decode_long() to read the ERL_SMALL_BIG_EXT
as long as it fits into a 32 bit signed integer.

> }  In R9C there will be a ei_decode_longlong() and ei_decode_ulonglong(),
> }  e.i. 64-bit integers.
>   
> I was wondering what would happen on a 64-bit emulator.

ei_decode_longlong() and ei_decode_long() will be exactly the same
function on a 64-bit emulator.

> The R9C changes sound good.  I can wait, in the mean time I'm just
> working around the limitation for an all ones 32 value.

Not for production code but you can always test the latest snapshot
from www.erlang.org,

kent



More information about the erlang-questions mailing list