View previous topic :: View next topic |
Author |
Message |
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
Comparing variables of different types |
Posted: Sat Aug 11, 2007 1:15 am |
|
|
Can I compare float and int?
for ex. if (float<int) |
|
|
Ttelmah Guest
|
|
Posted: Sat Aug 11, 2007 2:33 am |
|
|
Yes.
However the results will have the normal 'float' inaccuracies.
Basically, the 'int', will automatically be converted to a float, and then the comparison will be performed. This means the comparison will involve a lot more work.
If you just want to check if the float is 'past' an integer boundary, then consider converting the float to an integer, and performing the comparison on this. So:
if ((int16)float<int16)
This gives slightly faster performance (I have assumed your 'int', is an int16, since otherwise the range becomes very small...).
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|