1. 2

  2. 3

    Internally, this puts the number in a single-element Float64Array typed array and gets its buffer to read the value’s raw bits:

    (new Float64Array([n])).buffer

    Then it converts that buffer to a string of "1"s and "0"s by viewing the buffer as a Uint8Array and mapping each viewed byte to a binary string with .toString(2). Finally, it creates properties like exponent and mantissa by using [] array indexing, .substring, and .slice to extract the relevant bits.

    1. 1

      Similar to what asm.js and emscripten do. We even support negative zero correctly. :)