<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">I don't stuff will break from this, so
      I wouldn't consider it a bug per se.<br>
      <br>
      For instance,<br>
      7> erlang:term_to_binary(1 bsl 29).       <br>
      <<131,98,32,0,0,0>><br>
      <br>
      ok, but you could also define 1 bsl 29 = 536870912 as,<br>
      <<131,110,4,0,0,0,0,32>> (SMALL_BIG)<br>
      in the external format, so<br>
      <br>
      9> erlang:binary_to_term(<<131,110,4,0,0,0,0,32>>).<br>
      536870912<br>
      <br>
      The "proper" way to encode should probably be as you describe
      though but I think it correct external format encoded from ei ..
      erl_interface legacy, what a bundle of joy =)<br>
      <br>
      // Björn-Egil<br>
      <br>
      On 2013-12-16 16:25, Serge Aleynikov wrote:<br>
    </div>
    <blockquote
cite="mid:CANt451mnQJrPrb2E2denofzVstiRy5hpYryYi-sbF-KxA+K-NA@mail.gmail.com"
      type="cite">
      <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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-bugs mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-bugs">http://erlang.org/mailman/listinfo/erlang-bugs</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>