On 2008-07-26 08:05:16 -0400, Shoban Jayaraj <sh****@gmail.comsaid:
>
that prints
10000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0.0000
10000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0.0000
1.#INF
1.#INF
My
>
assumption is, as I am casting the doubles to float, it should als
print 1.#INF, but not so. Why?
There are two things that interact to produce this result.
First, when you pass an argument of type float as one of the extra
arguments to a function that takes a variable-length argument list,
that argument is promoted to double.
Second, unless you store a value in a variable, the compiler is allowed
to handle it at higher precision than its type calls for. On x86, for
example, floats and doubles are generally handled as 80-bit values,
rather than the 64 bits that a double uses, or the 32 bits that a float
uses.
So when you pass (float)d to printf, the compiler doesn't have to
truncate the value to float; it can simply passes it as a double, and
it looks like that's what's happening here. Same thing for the one with
the static_cast.
When you pass arguments that were stored as floats they are promoted to
double. Both f and f1 have the value infinity, and when they get
promoted to double they remain infinity.
--
Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(
www.petebecker.com/tr1book)