Sign in to follow this  

non-int mod operator in c++?

This topic is 4695 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

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


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