New course! Every coder should learn Generative AI!
Try a free lesson0
In c++, can the modulo operator (%) be applied directly to floating -point numbers? such as float or double?
cout << 5.0 % 2; If the compiler produces error, is there any way to do it? Can anyone please clarify?
2 Answers
+ 2
No because it doesn't make sense in real world mathematics.
Real numbers can go on infinitely, so there isn't a remainder.
fmod exists, but it may not give what you expect
https://cplusplus.com/reference/cmath/fmod/
+ 1
「HAPPY TO HELP」 thanks