Modulo Operator with floating point numbers

Apr 5, 2012 at 10:08am
Hi,

I was just wondering why modulo operator cannot be used with floating point numbers in C and C++. I am trying to know the reason behind it.

Any help would be really appreciated.

Thanks.
Apr 5, 2012 at 10:39am
The modulo operator returns that part of a division that is discarded (the remainder) in case of a non floating point operation.
So when you have floating point modulo doesn't make sense since nothing is discarded

e.g.

int:
155 % 100 = 55
155 / 100 = 1

floating point: 155 / 100 = 1.55
Apr 5, 2012 at 11:41am
If you want modulo for floating point number you can use std::fmod.
Topic archived. No new replies allowed.