Multiplicative Operators [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Reference Manual
Multiplicative Operators
The multiplicative operators perform multiplication (*), division (/), or
remainder (%).
Syntax
multiplicative-expression ::=
cast-expression
multiplicative-expression * cast-expression
multiplicative-expression / cast-expression
multiplicative-expression % cast-expression
Description
Each of the operands in a multiplicative expression must have arithmetic
type. Further, the operands for the % operator must have integral type.
The usual arithmetic conversions are performed on the operands to select
a resulting type. The result is not an lvalue.
The result of the multiplication operator * is the arithmetic product of
the operands.
The result of the division operator / is the quotient of the operands.
The result of the mod operator % is the remainder when the left argument
is divided by the right argument. By definition, a%b==a-((a/b)*b). The
second operand (/ or %) must not
be 0.
The following table describes the result of a/b for positive and negative
integer operands, when the result is inexact.
-----------------------------------------------------------------------------------------------
| | | |
| | b positive | b negative |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| a positive | Largest integer less than the true | Smallest integer greater than the |
| | quotient. | true quotient. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| a negative | Smallest integer greater than the | Largest integer less than the true |
| | true quotient. | quotient. |
| | | |
-----------------------------------------------------------------------------------------------
For example, -5/2 == -2. The true quotient is -2.5; the smallest integer
greater than -2.5 is -2.
The following table describes the sign of the result of a%b for positive
and negative operands, when the result is not zero.
-----------------------------------------------------------------------------------------------
| | | |
| | b positive | b negative |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| a positive | + | + |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| a negative | - | - |
| | | |
-----------------------------------------------------------------------------------------------
For example:
-5 % 2 == -1
Examples
var1 * var2
var1 / var2
var1 % var2
MPE/iX 5.0 Documentation