Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modulus division when first number is smaller than second number

I apologize if this is a simple question but I'm having trouble grasping the concept of modulus division when the first number is smaller than the second number. For example when 1 % 4 my book says the remainder is 1. I don't understand how 1 is the remainder of 1 % 4.
1 / 4 is 0.25. Am I thinking about modulus division incorrectly?

like image 852
Jessica M. Avatar asked May 01 '13 01:05

Jessica M.


People also ask

How do you find the modulus of the first number smaller?

If the numerator is smaller than the denominator, then the remainder is equal to the numerator. 3 % 10 =3 //If smaller number i.e. 3 is divided by bigger number i.e. 10, then the numerator becomes the remainder.

What comes first division or modulus?

Most programming languages adopt the convention that the modulo operator (denoted by % rather than mod ) occupies the same place in the order of operations as multiplication and division. Hence, it comes AFTER the operations in parentheses, but BEFORE addition and subtraction.

Can the result of a modulo operation be larger than the divisor?

Answer. No, the result of a modulo operation can never be larger than the divisor, assuming all positive values being used in the operation. If the division is done correctly, then the divisor was fitted into the dividend as many times as possible.


1 Answers

First, in Java, % is the remainder (not modulo) operator, which has slightly different semantics. That said, you need to think in terms of integer-only division, as if there were no fractional values. Think of it as storing items that cannot be divided: you can store zero items of size 4 in a storage of overall capacity one. Your remaining capacity after storing the maximum number of items is one. Similarly, 13%5 is 3, as you can fit 2 complete items of size 5 in a storage of size 13, and the remaining capacity is 13 - 2*5 = 3.

like image 198
misberner Avatar answered Oct 24 '22 19:10

misberner