Golang's math.Mod(10, 4) returns 2 -- ie. the integer part of division result 2.5 -- but shouldn't it be "the floating point remainder", that is, 0.5?
The MOD function takes as arguments two real number operands, and returns the remainder from integer division of the integer part of the first argument (the dividend) by the integer part of the second argument (the divisor). The value returned is an INT data type (or INT8 for remainders outside the range of INT).
Modulo or Remainder Operator returns the remainder of the two numbers after division. If you are provided with two numbers, say A and B, A is the dividend and B is the divisor, A mod B is there a remainder of the division of A and B.
Answer. Yes, the Python modulo operator will work with floating point numbers. This will take precedence, so will be either zero or a float.
3) modulus operator is not just applicable to integral types e.g. byte, short, int, long but also to floating-point types like float and double. 4) You can also use the remainder operator to check if a number is even or odd, or if a year is leap year.
The result is correct. math.Mod returns the remainder, which really is 2 in this case. It's equivalent to the % operator, but for floating point numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With