Найти значение выражения 11 mod 5
Обновлено: 22.12.2024
This opearation (or function) rounds a value downwards to the nearest integer even if it is already negative. The floor function returns the remainder with the same sign as the divisor. This is the method used in our calculator. See how it works by examples:
- floor(2.1); // returns number 2
- floor(2.7); // returns number 2
- floor(-5.2); // returns number -6
- floor(-5.7); // returns number -6
Some hints:
- a mod 1 is always 0;
- a mod 0 is undefined;
- Divisor (b) must be positive.
This function is used in mathematics where the result of the modulo operation is the remainder of the Euclidean division.
The first result in our calcultor uses, as stated above, the function floor() to calculate modulo as reproduced below:
a mod b = a - b × floor(a/b)
To understand how this operation works, we recommend reading What is modular arithmetic? from Khan Academy.
The Modulo Operator (%) in Some Programming Languages Like PHP and Javascript
In computers and calculators due to the various ways of storing and representing numbers the definition of the modulo operation depends on the programming language or the hardware it is running.
For example, in PHP $a % $b means 'a' modulo 'b'. In javascript, it is written as a % b. This symbol '%', in both languages, is called modulo operator. It simply returns the remainder of 'a' divided by 'b'. That explains the differences found in the calculator when 'a' (dividend) is negative and b isn't equal to 1. It is because a mod b isn't simply the remainder as returned by the operator '%'. See some examples:
Operation | a mod b | $a % $b |
---|---|---|
5 mod 3 | 2 | 2 |
3 mod 1 | 0 | 0 |
-5 mod 3 | 1 | -2 |
-3 mod 5 | 2 | -3 |
15 mod 12 | 3 | -3 |
29 mod 12 | 5 | 5 |
-4 mod 12 | 8 | -4 |
-13 mod 6 | 5 | -1 |
Notes:
There are some other definitions in math and other implementations in computer science according to the programming language and the computer hardware. Please see Modulo operation from Wikipedia.
Читайте также: