bignum support in ei?

Kent Boortz kent@REDACTED
Thu Jun 12 01:35:23 CEST 2003


Vance Shipley <vances@REDACTED> writes:
> How do I receive a bignum in ei?  Using ei_decode_long() doesn't work.

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.

> When I send integers and use ei_print_term() to see what was received
> and ei_get_type() to see the type I get the following:
> 
> Sent              Received                           Type
> ----------------  ---------------------------------  ---------------------
> 16#00000000       0                                  ERL_SMALL_INTEGER_EXT
> 16#00000001       1                                  ERL_SMALL_INTEGER_EXT
> 16#000000ff       1                                  ERL_SMALL_INTEGER_EXT
> 16#000001ff       65535                              ERL_INTEGER_EXT
> 16#00ffffff       16777215                           ERL_INTEGER_EXT
> 16#07ffffff       134217727                          ERL_INTEGER_EXT
> 16#08ffffff       #integer(2) = {65535,2303}         ERL_SMALL_BIG_EXT
> 16#ffffffff       #integer(2) = {65535,65535}        ERL_SMALL_BIG_EXT
> 16#fffffffffffff  #integer(3) = {65535,65535,65535}  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?

> The ei_get_type() function returns a size of 0 for ERL_SMALL_INTEGER_EXT
> and ERL_INTEGER_EXT but when the type is ERL_SMALL_BIG_EXT size is the
> number of elements in the tuple.  There is also an ERL_LARGE_BIG_EXT 
> type defined but I don't know how big a number you need to get it.
> 
> I see from the source that there is an ei_decode_bignum() however it is
> noted that it just skips past it.

In R9C there will be a ei_decode_longlong() and ei_decode_ulonglong(),
e.i. 64-bit integers.

R9C on Unix will also include support for GMP bignums that can be
enabled if you have the GMP library installed and configure before
compiling from source using

  --with-gmp=PATH         specify location of GNU MP include and lib
  --with-gmp              use GNU MP (will search for it)

Using GMP you can handle integers of all sizes,

kent


Ref: http://www.swox.com/gmp/

New functions (preleminary):

  int ei_decode_longlong(const char *buf, int *index, EI_LONGLONG *p);
  int ei_decode_ulonglong(const char *buf, int *index, EI_ULONGLONG *p);
  int ei_encode_longlong(char *buf, int *index, EI_LONGLONG p);
  int ei_encode_ulonglong(char *buf, int *index, EI_ULONGLONG p);
  int ei_x_encode_longlong(ei_x_buff* x, EI_LONGLONG n);
  int ei_x_encode_ulonglong(ei_x_buff* x, EI_ULONGLONG n);

  int ei_decode_bignum(const char *buf, int *index, mpz_t obj);
  int ei_encode_bignum(char *buf, int *index, mpz_t obj);
  int ei_x_encode_bignum(ei_x_buff *x, mpz_t obj);



More information about the erlang-questions mailing list