+ 1
What is reminder for 5.0 % 2?
What is reminder for 5.0 % 2?
7 Antworten
+ 6
it's an error
modular division is not applicable for float variables
+ 7
it is an error, modulus operator is only for integer-like data types in C/C++
+ 5
in case of 5%2 ans is 1
it is because modular division returns remainder
+ 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).
+ 1
probably because the result is intuitive, and python wants to be intuitive :)
0
if it is 5%2 it is simply 1