Discussion:
casting double -> float
(too old to reply)
Stephen Tu
2008-07-21 18:55:31 UTC
Permalink
i have a question off one of garcia's past midterms:
Q: The result of casting the double number
closest to -? (but is not -?) into a float.
A: -inf

i am not sure how double -> float casting works. the double closest to
-inf (correct me if i'm wrong please is):

1 11111111110 1111...1111 (52 1's)

(there is a zero in the rightmost bit of the exp since it if it were all
ones then it would be a reserved number (NaN). )

so when we cast this number to float, what happens? does it take the 8
most significant bits from the Exp and the 23 most sig bits, and make it
a 32 bit float (keeping the sign) ? how do they get -inf?

thanks
[Instr] Albert Chae
2008-07-21 23:19:28 UTC
Permalink
The cast will try to approximate the value of the double with
the limited bits in the float. If you have the most negative double,
it is far beyond the range of a single precision float so it is
cast to -inf.

Albert
Post by Stephen Tu
Q: The result of casting the double number
closest to -? (but is not -?) into a float.
A: -inf
i am not sure how double -> float casting works. the double closest to -inf
1 11111111110 1111...1111 (52 1's)
(there is a zero in the rightmost bit of the exp since it if it were all ones
then it would be a reserved number (NaN). )
so when we cast this number to float, what happens? does it take the 8 most
significant bits from the Exp and the 23 most sig bits, and make it a 32 bit
float (keeping the sign) ? how do they get -inf?
thanks
Loading...