The remainder of the float division

How to calculate the remainder of division of two float s?

+7
source share
2 answers

How about a-floor(a/b)*b - assuming a and b both positive?

We can say that the β€œremainder” is not the right concept for floating divisions, but I will leave it to my own opinion.

+7
source

Use fmod , which computes a floating point module.

 double remainder = fmod(a_double, another_double); 

If you want to use float instead of double , use fmodf .

+26
source

All Articles