non-int mod operator in c++?
5 replies to this topic
Members - Reputation: 122
Posted 11 March 2005 - 04:27 PM
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?
Moderators - Reputation: 1682
Posted 11 March 2005 - 08:58 PM
Original post by Mushu
For those of us who are blinded by any non-black backgrounded page:Quote:
// for doubles
fmod(double x, double y);
// for floats
fmodf(float x, float y);
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]