ast said:
when a and b are both integers, a % b is the reminder r of the
division of a by b. (a = bq+r, 0 <= r < b)
but % works with non integers data too, ie
5.6 % 3.21 = 2.39
Does anyone know what % does in this situation ?
Yes. (That is a stupid question!¹)
,-[ECMAScript Language Specification, Edition 5 Final²]
|
| 11.5.3 Applying the % Operator
|
| The % operator yields the remainder of its operands from an implied
| division; the left operand is the dividend and the right operand is
| the divisor.
|
| […]
| The result of an ECMAScript floating-point remainder operation is
| determined by the rules of IEEE arithmetic:
|
| • If either operand is NaN, the result is NaN.
| • The sign of the result equals the sign of the dividend.
| • If the dividend is an infinity, or the divisor is a zero, or both,
| the result is NaN.
| • If the dividend is finite and the divisor is an infinity,
| the result equals the dividend.
| • If the dividend is a zero and the divisor is finite, the result is
| the same as the dividend.
| • In the remaining cases, where neither an infinity, nor a zero, nor
| NaN is involved, the floating-point remainder r from a dividend n
| and a divisor d is defined by the mathematical relation
| r = n − (d * q) where q is an integer that is negative only if n/d
| is negative and positive only if n/d is positive, and whose
| magnitude is as large as possible without exceeding the magnitude
| of the true mathematical quotient of n and d.
HTH
PointedEars
___________
² <
http://www.catb.org/~esr/faqs/smart-questions.html>
¹ <
http://www.ecma-international.org/publications/files/
ECMA-ST/ECMA-262.pdf>