#INFs and casts

S

Shoban Jayaraj

Hi,

I have the following code:

#include <stdio.h>

int main(int argc, char **argv)
{
double d = 1.0e100;

float f = 1.0e100;

float f1 = d;

printf("%6.4f\n", static_cast<float>(d));

printf("%6.4f\n", (float)(d));

printf("%6.4f\n", f);

printf("%6.4f\n", f1);

return 0;
}

that prints

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.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?

Thanks in advance,
Shoban Jayaraj
 
S

Shoban Jayaraj

It's a bit compiler and option dependent. E.g. I suspect the compiler you're
using has an option /Op that will yield a slightly different result. The
language standard doesn't go into the result of such operations so it's purely a
Quality Of Implementation issue.

Thanks. /Op does change the results. I will look into the details of
this flag to get more info.

Reg,
Shoban Jayaraj
 

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
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top