Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So been working on this mathematical algorithm of checking if a numerical value is equal to a whole number 1,2,3,4,5 not a non-whole number 1.5,2.3,4.6.

I researched around and found out that one way to do this would be to :

if(numerical_value == static_cast<int>(numerical value)) 

Which I don't understand how that represents a whole number but still.

Another problem :

When using this code my video game starts running on really low FPS my question is why?.

If that code is being repeated every iteration of the loop and that is the main cause of the video game running on slow FPS then my more fascinating question would be what is a more efficient way to check if a numerical value is a whole number?.

By the way I am using integer values not floating point or double point precision.

Maybe the answer is right in my face and I don't see it?.

share|improve this question

closed as off topic by bobobobo, Byte56, Le Comte du Merde-fou, Sean Middleditch, bummzack Mar 18 '13 at 12:31

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I really don't want to discourage someone new, but the first part of your question is incredibly basic and the second part is impossible to answer without seeing more code - it could literally be caused by anything. – Le Comte du Merde-fou Mar 17 '13 at 14:36
If you're only performing game logic on whole-numbered frames your simulation will appear to be very very slow. – Mokosha Mar 17 '13 at 14:43
If you're only using integer values, everything is whole numbers. You can only have fractional values with floats and doubles (or a specialized rational number class). – Sean Middleditch Mar 17 '13 at 17:23

if you are using integers only then they are always whole numbers.

As for how the cast works. static_cast<int> interprets the value of the argument as an integer. Since integers represent only whole numbers a float or double value of 1.9535 will be interpreted as the integer 1 (note that there is no rounding, the part after the separator will just be ignored). If a variable is already a whole number the integer will represent the same number as the orignal value. Do note that floating point variables can not precisely represent each number (so that goes for doubles and floats) so this check might not always work since the floating point variable can not represent each whole number.

If you're only doing this once each loop it should not cause a lower frame rate. A static cast is very cheap.

share|improve this answer
What if this algorithm is within a struct member? – NoobScratcher Mar 17 '13 at 12:09
a 'struct member object'? What do you mean by that. Structures cant have methods in C++ if I recall correctly. – Roy T. Mar 17 '13 at 12:10
struct foostruct { void foo (int x, int y , int color);}; foostruct foostructobject;,2,0xffffff); foo is the member of struct foostruct. – NoobScratcher Mar 17 '13 at 12:11
Lets not chat here, please make a new question exactly explaining what you're trying to do, then me and others will give you a solid explanation. Maybe also link to this question explaining my suggestion for a new question. – Roy T. Mar 17 '13 at 12:26
@RoyT. The only difference between a struct and a class in C++ is that default accessibility of struct members is set to public. – Mokosha Mar 17 '13 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.