Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My Haskell is non-existent. Here's a solution in JavaScript. As others have noted, the key is to calculate the binary logarithm to get the exponent.</p> <p>From <a href="http://blog.coolmuse.com/2012/06/21/getting-the-exponent-and-mantissa-from-a-javascript-number/" rel="nofollow">http://blog.coolmuse.com/2012/06/21/getting-the-exponent-and-mantissa-from-a-javascript-number/</a></p> <p><pre></p> <code>function decodeIEEE64 ( value ) { if ( typeof value !== "number" ) throw new TypeError( "value must be a Number" ); var result = { isNegative : false, exponent : 0, mantissa : 0 }; if ( value === 0 ) { return result; } // not finite? if ( !isFinite( value ) ) { result.exponent = 2047; if ( isNaN( value ) ) { result.isNegative = false; result.mantissa = 2251799813685248; // QNan } else { result.isNegative = value === -Infinity; result.mantissa = 0; } return result; } // negative? if ( value &lt; 0 ) { result.isNegative = true; value = -value; } // calculate biased exponent var e = 0; if ( value &gt;= Math.pow( 2, -1022 ) ) { // not denormalized // calculate integer part of binary logarithm var r = value; while ( r &lt; 1 ) { e -= 1; r *= 2; } while ( r &gt;= 2 ) { e += 1; r /= 2; } e += 1023; // add bias } result.exponent = e; // calculate mantissa if ( e != 0 ) { var f = value / Math.pow( 2, e - 1023 ); result.mantissa = Math.floor( (f - 1) * Math.pow( 2, 52 ) ); } else { // denormalized result.mantissa = Math.floor( value / Math.pow( 2, -1074 ) ); } return result; } </code></pre>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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