CALC Examples


Example 1:

 

  

CALC

ANS=VAR1+VAR2+27.3

 

 

Variable

Format

Contents

Before:

ANS

5.2

•••85.10

 

VAR1

4.2

••10.15

 

VAR2

5.2

••100.05

 

After:

ANS

5.2

••137.50

 

Remaining variables are unchanged.

 

No Condition Flag is set.

 

Example 2:

 

  

CALC

ANS=(((( VAR1 + VAR2 ) / 10.5 ) - 2 ) * 2 )

 

 

Variable

Format

Contents

Before:

ANS

5.2

•••23.15

 

VAR1

2

•8

 

VAR2

3

••2

 

After:

ANS

5.2

•••-2.10

 

Remaining variables are unchanged.

 

The LESS Condition Flag is set.

 

Example 3:

 

  

CALC

ANS=( ( ANS + 1 ) * 2 )

 

 

Variable

Format

Contents

Before:

ANS

3

••5

 

After:

ANS

3

•12

 

No Condition Flag is set.

 

Example 4:

 

  

CALC

PERCENT=((AMOUNT/TOTAL)*100.00)

 

 

Variable

Format

Contents

Before:

AMOUNT

3

•55

 

TOTAL

3

122

 

PERCENT

3.2

•54.23

 

After:

PERCENT

3.2

•••.00

 

The result is zero. Since neither AMOUNT nor TOTAL contain a decimal digit, the operation is performed with integer precision, i.e., 55/122 = 0. The ZERO Condition Flag is set. If this same calculation were performed using the CALC statement, the result would be not be zero.

 

Example 5:

 

  

CALC

PERCENT=((AMOUNT*100.00)/TOTAL)

 

 

Variable

Format

Contents

Before:

AMOUNT

3

•55

 

TOTAL

3

122

 

PERCENT

3.2

•54.23

 

After:

PERCENT

3.2

•45.08

 

The result is not zero since the literal 100.00 contains a decimal point and it is involved in the first operation, the decimal precision is carried throughout the other operations. No Condition Flag is set.

 



PL/B Language Reference BYTE Examples CALL Examples