Jump to content
  • Advertisement
Sign in to follow this  
BloodLust666

% illegal with floats?

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

y can't i use % with floats??? for what i'm doing, there's no other way i could do it... well, there is, but it would take lots more code that i really don't want to do. Ok, basically, i have a float increasing by something like .15, then i have a constant that i want to see how many times goes into that float. long Num = 128 % myFloat; i keep getting an error saying "illegal right hand use of float" or something like that... anything else i can do?

Share this post


Link to post
Share on other sites
Advertisement
You can use the fmod() function from the cmath header. (math.h if this is C and not C++, and if it's not C or C++, I don't know.)

Share this post


Link to post
Share on other sites
Yeah It's kinda stupid really.
Anyone know why they didn't just make % do what fmod does?

Share this post


Link to post
Share on other sites
Because
(1) traditionally, modulo is only defined for the set of integers anyway, and
(2) because no-one has the guts to implement a hardware floating-point modulo. If you thought floating-point divide was terrifying...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!