Richard heathfields casting operation

J

jameskuyper

Chip said:
Is 3.0f required to be equal to (float)3.0 ?

No, and in general it won't be true. Try this:

#include <stdio.h>

int main(int argc, char *argv[])
{
float f = 0.1f;
double d = 0.1;
if (f == d)

That doesn't correspond to his question. Try the following instead:

if (f == (float)d)

I think you'll find that it works much better (though it's still not
guaranteed to work).,
 
K

Keith Thompson

Peter 'Shaggy' Haywood said:
Groovy hepcat Dik T. Winter was jivin' in comp.lang.c on Thu, 8 Nov 2007
12:18 pm. It's a cool scene! Dig it. [...]
Morover, the original did show how easy it is to get complex casts
right.

No, it showed how easy it is to get casts wrong. Hence the statement
that Philip "highlighted Yet Another Reason not to add spurious casts."

It did show how easy it is to get complex casts right -- i.e., not
very.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top