IEEEremainder (JavaScript)

Gets the remainder of a division according to IEEE 754.

Defined in

Math (JavaScript)

Syntax

IEEEremainder(f1:double, f2:double) : double
Parameter Description
f1 The dividend. See below for special cases.
f2 The divisor. See below for special cases.
Return value Description
double The remainder of the first parameter divided by the second. See below for the exact computation.

Usage

The remainder is f1 - (f2 * n), where n is rint(f1 / f2).

This algorithm yields a positive remainder where rint(f1 / f2) rounds down and a negative remainder where rint(f1 / f2) rounds up. For example, rint(13 / 4) = +3 (rounding down) and 13 - (4 * 3) = 1. But rint(13 / 5) = 3 (rounding up) and 13 - (5 * 3) = -2.

If the remainder is zero, its sign is the same as the dividend.

Special cases are as follows:
  • The following yield NaN:
    • dividend or divisor NaN
    • dividend Infinity
    • divisor 0
  • The following yield the dividend:
    • divisor Infinity
    • divisor Number.MAX_VALUE
  • The following yields 0: divisor Number.MIN_VALUE.

Examples

This edit box onblur event calculates the rounded quotient and the remainder of a dividend and divisor..
sessionScope.quotient = Math.rint(
	sessionScope.dividend / sessionScope.divisor);
sessionScope.remainder = Math.IEEEremainder(
	sessionScope.dividend, sessionScope.divisor);