I have recently started learning code (Java), and have looked up the modulus operator on the Oracle website, as per the section 15.17.3. of the following link:
http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.17.3
Basically, if a
is the denominator, and b
is the nominator, it states that: (a/b) * b + (a%b) = a
, which defines the modulus operator as: a%b = a – (a/b) * b
.
I am confused because the equation simply does not work, which can be simplified as a%b = 0
. I know my basic math algebra, so I am hoping if someone can enlighten me on how is it supposed to equal?
For integers, operator /
means integral division, not mathematical one, for example:
7/2 = 3
6/2 = 3
5/2 = 2
4/2 = 2
3/2 = 1
2/2 = 1
1/2 = 0
In math terms, formula from java spec will be written like:
⌊a/b⌋ * b + (a%b) = a
a%b = a – ⌊a/b⌋ * b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.