non-int mod operator in c++?
It seems that the mod operator in C++ will not work on anything but ints. For example:
remainder = 130.7 % 50;
gives an error, not remainder = 30.7
Is there a way to get the mod operator to take a double data type, or do I just need to do it manually and write my own "double mod" function?
For those of us who are blinded by any non-black backgrounded page:
[wink]
Quote:#include <math.h>
// for doubles
fmod(double x, double y);
// for floats
fmodf(float x, float y);
[wink]
Quote:Original post by smart_idiot
fmod
[lol] I was thinking of FMOD the sound library. I was like wow, what an 'idiot' [grin]. I should get some sleep now.
Quote:Original post by Mushu
For those of us who are blinded by any non-black backgrounded page:Quote:#include <math.h>
// for doubles
fmod(double x, double y);
// for floats
fmodf(float x, float y);
[wink]
Except that of course in C++ you want to include <cmath> instead, and (I think?) import the function names (or qualify them each time) from the std namespace. [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement