Q on casting and precision

K

kj

Let INT_TYPE stand for some "integer type", like int or long. And
let WIDEST_FLOAT_TYPE stand for the widest float type available,
double, or long double, or whatever. Now suppose that, in the code
below, x is of type INT_TYPE.

Does the standard require that the following expression always
evaluate to true?

x == (INT_TYPE) (WIDEST_FLOAT_TYPE) x;

TIA!

kj
 
B

Ben Pfaff

kj said:
Let INT_TYPE stand for some "integer type", like int or long. And
let WIDEST_FLOAT_TYPE stand for the widest float type available,
double, or long double, or whatever. Now suppose that, in the code
below, x is of type INT_TYPE.

Does the standard require that the following expression always
evaluate to true?

x == (INT_TYPE) (WIDEST_FLOAT_TYPE) x;

No. Consider an instantiation with 64-bit INT_TYPE and 64-bit
WIDEST_FLOAT_TYPE. Some bits of the float type will be used for
the exponent, so it have fewer than 64 significant bits and
precision will be lost by the conversion.
 
K

kj

No. Consider an instantiation with 64-bit INT_TYPE and 64-bit
WIDEST_FLOAT_TYPE. Some bits of the float type will be used for
the exponent, so it have fewer than 64 significant bits and
precision will be lost by the conversion.

I see. Thanks!

kj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,200
Latest member
LaraHunley

Latest Threads

Top