In c++, can the modulo operator (%) be applied directly to floating -point numbers? such as float or double? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
+ 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
ŃÇî´╝Ę´╝í´╝░´╝░´╝╣ ´╝┤´╝» ´╝Ę´╝ą´╝Č´╝░ŃÇŹ
ŃÇî´╝Ę´╝í´╝░´╝░´╝╣ ´╝┤´╝» ´╝Ę´╝ą´╝Č´╝░ŃÇŹ - avatar