Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>num2bit: By setting the 51st and 52nd bit to 1, this forces the exponent to be a specific number (otherwise there would be overflow) - then when you return (int32_t)o.u32.lo you know you are getting an integer back with the same value as the 'low 32 bits' of the double since the exponent is fixed. So, this is a trick to get the integer value of most doubles quickly. It looks like it would truncate off numbers after the decimal point by doing this, and it would have unexpected effects if it was 2^51 or larger to begin with.</p> <pre><code>&gt;&gt;&gt; math.frexp(1.0 + 6755399441055744.0) (0.7500000000000001, 53) &gt;&gt;&gt; math.frexp(0.0 + 6755399441055744.0) (0.75, 53) &gt;&gt;&gt; math.frexp(564563465 + 6755399441055744.0) (0.7500000626791358, 53) &gt;&gt;&gt; math.frexp(-564563465 + 6755399441055744.0) (0.7499999373208642, 53) &gt;&gt;&gt; math.frexp(1.5 + 6755399441055744.0) (0.7500000000000002, 53) &gt;&gt;&gt; math.frexp(1.6 + 6755399441055744.0) (0.7500000000000002, 53) &gt;&gt;&gt; math.frexp(1.4 + 6755399441055744.0) (0.7500000000000001, 53) </code></pre> <p>EDIT: The reason why both the 51st and 52nd bit are set is because if you only set the 52nd bit, then negative numbers would cause the exponent to change:</p> <pre><code>&gt;&gt;&gt; math.frexp(0 + 4503599627370496.0) (0.5, 53) &gt;&gt;&gt; math.frexp(-543635634 + 4503599627370496.0) (0.9999998792886404, 52) </code></pre> <p>num2u64: No clue. But the first number is 2^63 and the second is 2^64. It's probably to prevent overflow or signedness failure when casting a double larger than 2^63 to its integer representation, but I can't tell you more.</p>
 

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