HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 5 Expressions

Multiplicative Operators

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

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.

Table 5-2 “Results for Inexact a/b” describes the result of a/b for positive and negative integer operands, when the result is inexact.

Table 5-2 Results for Inexact a/b

b positive

b negative

a positive

Largest integer less than the true quotient.

Smallest integer greater than the true quotient.

a negative

Smallest integer greater than the true quotient.

Largest integer less than the true quotient.

 

For example, -5/2==-2. The true quotient is -2.5; the smallest integer greater than -2.5 is -2.

Table 5-3 “Results for Non-zero ab” describes the sign of the result of a%b for positive and negative operands, when the result is not zero.

Table 5-3 Results for Non-zero ab

b positive

b negative

a positive

+

+

a negative

-

-

 

For example:

     -5 % 2 == -1

Examples

var1 * var2

var1 / var2

var1 % var2