<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello Jesper,<br>
<br>
There seems to be a bug in the generic c-code for
binary/list_to_integer for that specific value where a bignum is
returned when a small should have been returned. If no-one feels
like submitting a patch to fix it, I'll take a look later this week.<br>
<br>
Thanks for the bug report!<br>
<br>
Lukas<br>
<div class="moz-cite-prefix">On 18/08/14 14:36, Jesper Louis
Andersen wrote:<br>
</div>
<blockquote
cite="mid:CAGrdgiV_qU-b5_Wot11uzo6g-7hTLPURNo5vVswfVyhNwP4QKQ@mail.gmail.com"
type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>While working on transit-erlang, Isaiah Peng and I found
what we believe to be a bug in the Erlang compiler:</div>
<div><br>
</div>
<div>
<div>9> A = -576460752303423488.</div>
<div>-576460752303423488</div>
<div>10> B = binary_to_integer(integer_to_binary(A)).</div>
<div>-576460752303423488</div>
<div>11> A == B.</div>
<div>false</div>
<div>12> A.</div>
<div>-576460752303423488</div>
<div>13> B.</div>
<div>-576460752303423488</div>
<div>14></div>
<div><br>
</div>
<div>I expected command 11 (A == B) to return true, as the
numbers are the same. But it looks like constants are not
treated the same way as converted vaues for some reason and
the equality test fails.</div>
<div><br>
</div>
<div>This fails in the interpreter and in compiled code. It
*also* fails with list_to_integer/1 and integer_to_list/1.
The number is not chosen arbitrarily. It is -1 * 2^59 which
is a borderline number on a 64bit machine. (OTP release
17.1). Isaiah notes that these borderline numbers are not
caught by the OTP test cases. They probably should be.</div>
<div><br>
</div>
<div>In the interest of full exploration, I've written a
QuickCheck test case to catch the remaining trouble. It
explicitly tests the borderline numbers and only finds this
error.</div>
<div><br>
</div>
<div>
<a moz-do-not-send="true"
href="https://gist.github.com/jlouis/52b68d9d4150af3bd00c">https://gist.github.com/jlouis/52b68d9d4150af3bd00c</a></div>
<div><br>
</div>
<div>
<pre class="" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;width:10759px;color:rgb(51,51,51);line-height:16.799999237060547px">
<div class="" id="file-integer_coding-erl-LC1"><pre style="color:rgb(0,0,0);line-height:normal;word-wrap:break-word;white-space:pre-wrap">-module(integer_coding).
-compile(export_all).
-include_lib("eqc/include/eqc.hrl").
power(_N, 0) -> 1;
power(N, P) -> N * power(N, P-1).
perturb() ->
elements([0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5]).
sign() ->
elements([1, -1]).
nat_power() ->
frequency([{1, elements([27, 28, 29, 31, 32, 33, 59, 60, 61, 63, 64, 65])},
{1, nat()}]).
interesting_int() ->
?LET({K, Sign, Perturb}, {nat_power(), sign(), perturb()},
power(2, K)*Sign + Perturb).
prop_binary_iso() ->
?FORALL(K, interesting_int(),
begin
I = binary_to_integer(integer_to_binary(K)),
I == K
end).
prop_list_iso() ->
?FORALL(K, interesting_int(),
begin
I = list_to_integer(integer_to_list(K)),
I == K
end).
all() ->
eqc:module({numtests, 3000}, ?MODULE).
t() ->
eqc:quickcheck(eqc:testing_time(300, prop_binary_iso())).
[...]
Produces:
8> integer_coding:all().
prop_list_iso: ..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................!
..........
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Failed! After 1498 tests.
-576460752303423488
prop_binary_iso: ...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................Failed! After 588 tests.
-576460752303423488
[prop_list_iso,prop_binary_iso]
9></pre></div><div class="" id="file-integer_coding-erl-LC55"><span class="" style="font-weight:bold">
</span></div></pre>
</div>
<div><br>
</div>
-- <br>
J.
</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>