+ 1

What is reminder for 5.0 % 2?

What is reminder for 5.0 % 2?

31st Jul 2017, 6:50 PM
Abhijeet Jha
Abhijeet Jha - avatar
7 Respuestas
+ 6
it's an error modular division is not applicable for float variables
1st Aug 2017, 5:52 AM
Shwati Kumari
Shwati Kumari - avatar
+ 7
it is an error, modulus operator is only for integer-like data types in C/C++
31st Jul 2017, 7:26 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 5
in case of 5%2 ans is 1 it is because modular division returns remainder
2nd Aug 2017, 1:01 AM
Shwati Kumari
Shwati Kumari - avatar
+ 3
In C++ you use fmod() for floats. (In math.h). I suppose it could be an optimization since it may have been more common to use it on integers. (This is speculation). Pretty sure remainders were originally meant to refer to integers anyway (in mathematics).
1st Aug 2017, 12:40 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
probably because the result is intuitive, and python wants to be intuitive :)
31st Jul 2017, 9:51 PM
maddin manek
maddin manek - avatar
0
if it is 5%2 it is simply 1
1st Aug 2017, 12:51 PM
Debby
Debby - avatar