Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remainder of float division

Tags:

objective-c

How do I compute the remainder of the division of two floats?

like image 425
aneuryzm Avatar asked Nov 28 '11 15:11

aneuryzm


2 Answers

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

You could say that "remainder" is not a proper concept for float divisions, but I'll leave that to your own judgment.

like image 163
Monolo Avatar answered Oct 12 '22 08:10

Monolo


Use fmod, which computes the floating point modulus.

double remainder = fmod(a_double, another_double);

If you want to use float instead of double you'd use fmodf instead.

like image 44
DarkDust Avatar answered Oct 12 '22 08:10

DarkDust