cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
user name:
password:
Forgot your password?
please wait
try again
cancel
forgot your password?
sign up
log in
[Legacy version]
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Modulo Operator with floating point numb
Modulo Operator with floating point numbers
Apr 5, 2012 at 10:08am
Apr 5, 2012 at 10:08am UTC
ramakrishnaprasad
(1)
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
Apr 5, 2012 at 10:39am UTC
coder777
(8448)
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
Apr 5, 2012 at 11:41am UTC
Peter87
(11244)
If you want modulo for floating point number you can use std::fmod.
Topic archived. No new replies allowed.