I have slightly modified the original message with a second question :
I have been advised by a C++ expert to ckeck that out : https://en.cppreference.com/w/cpp/numeric/bit_cast
to understand better the representation of double
, memcpy
, and bit_cast (C++20)
.
Here more specifically, I try to understand why we have that result from the code :
constexpr std::uint64_t u64v2 = 0x3fe9000000000000ull;
constexpr auto f64v2 = std::bit_cast<double>(u64v2);
"f64::from_bits(0x3fe9000000000000u64) == 0.781250f64"
Prior to it, I spent time to study the example which is provided in the example of fast inverse square root.
https://en.wikipedia.org/wiki/Fast_inverse_square_root#CITEREFGoldberg1991
I did the calculus manually, and it turns out that I finally realised what happens in this specific case with an exponent of 8 bits and a mantissa of 23 bits.
But in the example I mentioned above as an application of bit_cast
, it seems according to my research that the exponent is 11 bits, the mantissa 52 bits (with double precision) :
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
When I did the calculs by hand, I found
x = (1+Mx/L)*2^(Ex-B)
with
L=2^52 and Ex = 2*(2^9- 1) with the notations of
https://en.wikipedia.org/wiki/Fast_inverse_square_root#CITEREFGoldberg1991
And I don't find the result of `0.781250 as it is announced. Maybe the exponent and mantissa I choosed was not correct. I don't know, but I really would like to understand what happens.
Thanks in advance for your explanations to help to be to find 0.781250
2nd question : please can you check the question i have asked below as reply to the comment because even I have a challenge with the first example. thanks in advance