<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I believe there's a bug in the definition of ERL_MIN, ERL_MAX:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
<br></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace"><b>grep -n -A1 ERL_MAX lib/erl_interface</b>/src/legacy/erl_eterm.h</font></div><div class="gmail_default"><font face="courier new, monospace">28:#define ERL_MAX_COUNT 0xffffff</font></div>
<div class="gmail_default"><font face="courier new, monospace">29:#define ERL_MAX ((1 << 27)-1)</font></div><div class="gmail_default"><font face="courier new, monospace">30-#define ERL_MIN -(1 << 27)</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif">The macros are used by lib/erl_interface/src/encode/encode_longlong.c:</span><font face="arial, helvetica, sans-serif"><br>
</font></div><div class="gmail_default"><span style="font-family:arial,helvetica,sans-serif"><br></span></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace"><b>grep -n -B3 -A5 ERL_MAX lib/erl_interface/src/encode/encode_longlong.c </b></font></div>
<div class="gmail_default"><font face="courier new, monospace">63- put8(s,ERL_SMALL_INTEGER_EXT);</font></div><div class="gmail_default"><font face="courier new, monospace">64- put8(s,(p & 0xff));</font></div>
<div class="gmail_default"><font face="courier new, monospace">65- }</font></div><div class="gmail_default"><font face="courier new, monospace">66: } else if ((p <= ERL_MAX) && (p >= ERL_MIN)) {</font></div>
<div class="gmail_default"><font face="courier new, monospace">67- /* FIXME: Non optimal, could use (p <= LONG_MAX) && (p >= LONG_MIN)</font></div><div class="gmail_default"><font face="courier new, monospace">68- and skip next case */</font></div>
<div class="gmail_default"><font face="courier new, monospace">69- if (!buf) s += 5;</font></div><div class="gmail_default"><font face="courier new, monospace">70- else {</font></div><div class="gmail_default"><font face="courier new, monospace">71- put8(s,ERL_INTEGER_EXT);</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">It seems to me that these definitions are obsolete as the VM encodes integers up to (1 << 31)-1 as ERL_INTEGER_EXT (98), and only above that as ERL_SMALL_BIG (110):</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace">1> term_to_binary(1 bsl 31 - 1).</font></div>
<div class="gmail_default"><font face="courier new, monospace"><<131,98,127,255,255,255>></font></div><div class="gmail_default"><font face="courier new, monospace">2> term_to_binary(1 bsl 31).</font></div>
<div class="gmail_default"><font face="courier new, monospace"><<131,110,4,0,0,0,0,128>></font></div><div class="gmail_default"><br></div><div class="gmail_default">So the proper defines should be:</div><div class="gmail_default">
<br></div><div class="gmail_default"><b style="font-family:'courier new',monospace">lib/erl_interface</b><span style="font-family:'courier new',monospace">/src/legacy/erl_eterm.h:29:</span><br></div><div class="gmail_default">
<div class="gmail_default"><font face="courier new, monospace">#define ERL_MAX ((1 << <b><u>31</u></b>)-1)</font></div><div class="gmail_default"><font face="courier new, monospace">#define ERL_MIN -(1 << <b><u>31</u></b>)</font></div>
<div><font face="courier new, monospace"><br></font></div></div></div></div><div class="gmail_default">Serge</div><div class="gmail_default"><br></div></div>