<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Turns out that a number of other BIFs are not 64-bit safe, rand(), order(), to_int() are examples.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Filing a bug report.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 23, 2018 at 12:08 PM, Jim Mellander <span dir="ltr">&lt;<a href="mailto:jmellander@lbl.gov" target="_blank">jmellander@lbl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi all:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The attached brogram demonstrates that the bro sort() function does not sort correctly under certain circumstances (tested on OS/X &amp; Linux).  The behavior also occurs when using the common function idiom of sort(myvec, function(a: int, b: int): int { return a-b;});</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I haven&#39;t examined bro source code, but since some of the test values are larger than 32 bits, I surmise that there is a casting from 64 to 32 bits that could change the sign of the comparison, thus causing this problem.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Mitigation is to use a function that returns the sign of subtraction results, rather than the actual subtraction results, something like sort(myvec, function(a: int, b: int): int { return a&lt;b ? -1 : (a&gt;b ? 1 : 0);});</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Cheers,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Jim Mellander</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">ESNet</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div>
</blockquote></div><br></div>