In c++, can the modulo operator (%) be applied directly to floating -point numbers? such as float or double? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?

22nd May 2024, 2:39 AM
Moon
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/
22nd May 2024, 3:20 AM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
22nd May 2024, 3:52 PM
Moon