# modulo(%) operation with double

• 06-19-2009
jpnavarini
modulo(%) operation with double
I would like to do an operation like:

double a, b, c;

a = (b % c);

But Gcc doesn't allow me to do it, because it says % operation can't be used with double. (Invalid operands to binary %).

How can I do the modulo operation without using % or using the % and double types.

Thanks,

Joćo Pedro
• 06-20-2009
zacs7
With modf() from math.h of course.
modf - C++ Reference
• 06-20-2009
iMalc
The reason for this is that there is no remainder when performing division with a type capable of representing the actual answer.
E.g.
11 / 4 => 2, remainder 3 (where 3 = 11 % 4)
but 11.0 / 4.0 = 2.75, no remainder ever!
• 06-20-2009
ninety3gd
Quote:

The reason for this is that there is no remainder when performing division with a type capable of representing the actual answer.
E.g.
11 / 4 => 2, remainder 3 (where 3 = 11 % 4)
but 11.0 / 4.0 = 2.75, no remainder ever!

You can use % with C# or Java with real values...
• 06-20-2009
Sharke
Why doesn't C just do an automatic conversion from double to int in this case?
• 06-20-2009
ಠ_ಠ
because you would lose your decimal values