Multiplication ( * )

Division ( / )

Modulus ( % )

Navigation Aids -- This Page | Navigation Aids -- This Topic | Navigation Aids -- This Site | ||
---|---|---|---|---|

- IEEE Standard for Binary Floating-Point Arithmetic (Std. 754-1985)
- multiplication operator
- division operator
- modulus operator
- number operand
- precedence
- associativity
- binary operator
- NaN
- infinity
- Synonyms:
- Arithmetic Operators: Multiplicative operators are a sub-set of arithmetic operators. Arithmetic Operators includes both the additive and multiplicative operators. Note that the multiplicative operators have a higher precedence than the additive operators.
- Remainder Operator: Another name for the modulus operator.

This page will show the basic rules for JavaScript multiplicative operator group. In addition, type conversions are discussed where applicable. Some special situation cases are explained. And finally, some scripting examples are provided with comments.

- The multiplicative operators are binary operators. They have a "left to right" associatively and a precedence of 13.
- The multiplicative operators can have floating-point or integer operands.
- The multiplication operator performs multiplication, producing a product from its two operands.
- The division operator performs division, producing a quotient from its two operands. The left operand is the dividend and the right operand is the divisor.
- The modulus operator produces a remainder from its two operands by an implied division. The left operand is the dividend and the right operand is the divisor.
- What determines the sign of the result?
- Multiplication: The sign of the product is positive when both operands have the same sign. The product is negative when the operands have different signs.
- Division: The sign of the result is positive if both operands have the same sign. The sign of the result is negative if the operands have the different signs.
- Modulus: The sign of the result is the same as the sign of the dividend.

- The multiplicative operators handle rounding, overflow, and other floating-point arithmetic according to the IEEE Standard for Binary Floating-Point Arithmetic - 754-1985.

- Multiplication
- The result is NaN when either operand is NaN.
- The result is NaN when multiplying an infinite by zero.
- The result is infinity when multiplying an infinite by an infinite.
- The result is infinity when multiplying an infinite by a finite non-zero. If the finite non-zero of the second operand is negative, the result will be -infinity.
- The result is infinity when the magnitude of the product is too large to represent.
- The result is zero when the magnitude of the product is too small to represent.

- Division
- The result is NaN when either operand is NaN.
- The result is NaN when both operands are infinity.
- The result is NaN when both operands are zero.
- The result is infinity when dividing an infinity by zero.
- The result is infinity when dividing an infinity by non-zero finite.
- The result is infinity when dividing a non-zero finite by zero.
- The result is zero when dividing an finite by an infinite.

- Modulus
- The result is NaN when either operand is NaN.
- The result is NaN when the dividend is infinity or the divisor is zero.
- The result equals the dividend when the dividend is finite but the divisor is infinite.
- The result is zero when the dividend is zero but the divisor is finite.

Expression | Result | Comment |
---|---|---|

5 * 1.1 | 5.5 | floating point example |

5 * 0 | 0 | either operand is zero, the result is zero |

-5 * -2 | 10 | two negative operands make a positive result |

5 * -2 | -10 | opposite signed operands make a negative result |

10 / 4 | 2.5 | floating point example |

10 / 0 | infinity | The result is infinity when dividing a non-zero finite by zero. |

0 / 0 | NaN | The result is NaN when both operands are zero. |

2007 % 4 | 3 | the remainder is 3 after dividing 2007 by 4 |

6.3 % 3.1 | .1 | floating point example |

-6.3 % 3.1 | -0.1 | The sign of the result is the same as the sign of the dividend. |