I tried to implement float_twice(float_bits x)
in C, which multiplies x
by 2 in bit-level.
I compared the result of float_twice and the real float multiplication implemented in C, but found a difference.
float_twice(0X800001)
yields 0X1000001
, and this seems correct to me. As long as I understand, 0X80001
is a floating point representation of exponent 1
, and fractional part 1
. Since it is a normalized value, I believe adding one to the exponent part is sufficient.
However, ((float) 0X800001) * 2.0
yields 0X1000002
.
This seems to be a multiplication of unsigned integers, not float values.
To summarize, these are my questions,
What is the correct output for
float_twice(0X800001)
?If the correct output is
0X1000001
, why does C compute((float) 0X800001) * 2.0
as0X1000002
?