3. The difference between surplus and modulus of JavaScript

1. Seeking:

Touch is equal to y-n * x, n is the quotient after y / x (to be rounded down): the value of the touch is calculated to be the same as x

7/3, n = 7/3 is 2.3333, rounded down to 2, so n equals 2

So 7/3 touch is 7-2 * 3 = 1

 

7 / (-3), n = 7 / (-3) is -2.3333, rounded down to -3, so n is equal to -3

So the touch of 7 / (-3) is 7-(-3) * (-3) = -2

 

2. Find the remainder:

The remainder is equal to y-n * x, n is the quotient after y / x (to be rounded to 0): the value of the remainder is the same as y

The remainder of 7/3, n = 7/3 is 2.3333, rounded to 0 is 2, so n is equal to 2

So the remainder of 7/3 is 7-2 * 3 = 1

 

The remainder of 7 / (-3), n = 7 / (-3) is -2.3333, rounded to 0 is -2, so n is equal to -2

So the remainder of 7 / (-3) is 7-(-3) * (-2) = 1

Guess you like

Origin www.cnblogs.com/lanshanxiao/p/12734915.html