Background
IEEE 754 Double-precision floating-point format is a way to represent real numbers with 64 bits. It looks like the following:
A real number n
is converted to a double
in the following manner:
- The sign bit
s
is 0 if the number is positive, 1 otherwise. - The absolute value of
n
is represented in the form2**y * 1.xxx
, i.e. a power-of-2 times a base. - The exponent
e
isy
(the power of 2) plus 1023. - The fraction
f
is thexxx
part (fractional part of the base), taking the most significant 52 bits.
Conversely, a bit pattern (defined by sign s
, exponent e
and fraction f
, each an integer) represents the number:
(s ? -1 : 1) * 2 ** (e - 1023) * (1 + f / (2 ** 52))
Challenge
Given a real number n
, output its 52-bit fraction part of the double
representation of n
as an integer.
Test Cases
0.0 => 0
16.0 => 0
0.0625 => 0
1.2 => 900719925474099 (hex 3333333333333)
3.1 => 2476979795053773 (hex 8cccccccccccd)
3.5 => 3377699720527872 (hex c000000000000)
10.0 => 1125899906842624 (hex 4000000000000)
1234567.0 => 798825262350336 (hex 2d68700000000)
1e-256 => 2258570371166019 (hex 8062864ac6f43)
1e+256 => 1495187628212028 (hex 54fdd7f73bf3c)
-0.0 => 0
-16.0 => 0
-0.0625 => 0
-1.2 => 900719925474099 (hex 3333333333333)
-3.1 => 2476979795053773 (hex 8cccccccccccd)
-3.5 => 3377699720527872 (hex c000000000000)
-10.0 => 1125899906842624 (hex 4000000000000)
-1234567.0 => 798825262350336 (hex 2d68700000000)
-1e-256 => 2258570371166019 (hex 8062864ac6f43)
-1e+256 => 1495187628212028 (hex 54fdd7f73bf3c)
You can check other numbers using this C reference which uses bit fields and a union.
Note that the expected answer is the same for +n
and -n
for any number n
.
Input and Output
Standard rules apply.
Accepted input format:
- A floating-point number, at least having
double
precision internally - A string representation of the number in decimal (you don't need to support scientific notation, since you can use
1000...00
or0.0000...01
as input)
For output, a rounding error at the least significant bit is tolerable.
Winning Condition
This is code-golf, so the lowest bytes in each language wins.