Note that there are some explanatory texts on larger screens.

plurals
  1. POSame function in javascript and php giving different output
    primarykey
    data
    text
    <p>Function in javascript:</p> <pre><code>function int64add(dst, x, y) { var w0 = (x.l &amp; 0xffff) + (y.l &amp; 0xffff); var w1 = (x.l &gt;&gt;&gt; 16) + (y.l &gt;&gt;&gt; 16) + (w0 &gt;&gt;&gt; 16); var w2 = (x.h &amp; 0xffff) + (y.h &amp; 0xffff) + (w1 &gt;&gt;&gt; 16); var w3 = (x.h &gt;&gt;&gt; 16) + (y.l &gt;&gt;&gt; 16) + (w2 &gt;&gt;&gt; 16); dst.l = (w0 &amp; 0xffff) | (w1 &lt;&lt; 16); dst.h = (w2 &amp; 0xffff) | (w3 &lt;&lt; 16); } </code></pre> <p>I converted this javascript to PHP as: Function in PHP:</p> <pre><code>function int64add($dst, $x, $y) { $w0 = ($x-&gt;l &amp; 0xffff) + ($y-&gt;l &amp; 0xffff); $w1 = ($x-&gt;l &gt;&gt; 16) + ($y-&gt;l &gt;&gt; 16) + ($w0 &gt;&gt; 16); $w2 = ($x-&gt;h &amp; 0xffff) + ($y-&gt;h &amp; 0xffff) + ($w1 &gt;&gt; 16); $w3 = ($x-&gt;h &gt;&gt; 16) + ($y-&gt;l &gt;&gt; 16) + ($w2 &gt;&gt; 16); $dst-&gt;l = ($w0 &amp; 0xffff) | ($w1 &lt;&lt; 16); $dst-&gt;h = ($w2 &amp; 0xffff) | ($w3 &lt;&lt; 16); } </code></pre> <p>these two function return different output for same input. Tried searching over internet but couldn't find anything. Please help!</p> <p><strong>In JS:</strong></p> <p>Input:</p> <p>dst:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>x:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>y:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>returns:</p> <pre><code>int64{ h=-736899889, l=-411463152 } </code></pre> <p><strong>IN PHP:</strong></p> <p>Input:</p> <p>dst:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>x:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>y:</p> <pre><code>int64{ h=1779033703, l=-205731576 } </code></pre> <p>returns:</p> <pre><code>int64{ h=-736899891, l=-411463152 } </code></pre> <p><strong>Class int64 in php:</strong></p> <pre><code>class int64{ var $h; var $l; function int64($h,$l){ $this-&gt;h=$h; $this-&gt;l=$l; } } </code></pre> <p><strong>Function int64 in js:</strong></p> <pre><code> function int64(h,l){ this.h=h; this.l=l; } </code></pre> <p><strong>I want PHP to give output as Javascript. (Javascript is the correct one)</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload