Skip to content

Instantly share code, notes, and snippets.

View NoahAndrews's full-sized avatar

Noah Andrews NoahAndrews

View GitHub Profile
@NoahAndrews
NoahAndrews / multiplyFloat.js
Last active July 23, 2024 03:13 — forked from wchargin/multiplyFloat.js
multiply bigint by float in JS (spoiler alert: BigInt has no useful functions)
// Copied under the MIT license from https://gist.githubusercontent.com/wchargin/93062064e1ec0e3383b91b921da86048/raw/191a10b5ea5169a6c5c436a172353002e653b04c/multiplyFloat.js
/**
* For a finite normal 64-bit float `f`, extracts integers `sgn`,
* `exponent`, and `mantissa` such that:
*
* - `sgn` is -1 or +1
* - `exponent` is between -1023 and 1024, inclusive
* - `mantissa` is between 0 and 2^51 - 1, inclusive
* - the number given by `f` equals `sgn * 2^exponent * (1 + mantissa / 2^52)`