18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Programming</strong> <strong>Language</strong> Concepts<br />

Where double variables are supported, conversions between double and integer modes follow<br />

the same procedures as conversions between integer and real. Hence, expressions mixing<br />

integer and double arithmetic operations follow the procedure outlined above for mixed<br />

integer and real expressions.<br />

Expressions containing mixed double and real variables are evaluated to yield a double precision<br />

result, which may be automatically converted to the real mode, if necessary. When required<br />

by context, as in mixed real and double mode expressions, real values are automatically converted<br />

to double before evaluation.<br />

If, in the following examples, R has been defined as a real variable and D as a double variable,<br />

then in executing the statement:<br />

let D = D + R<br />

R is converted to double before the addition, which produces a double precision result, while:<br />

let R = R * D<br />

converts R to double before the multiplication, but the result is truncated to real before reassignment.<br />

As may be seen, the provision of different modes of variable representation brings with it some additional<br />

complexity. A variable defined with a certain mode can only be used in ways consistent<br />

with its definition. In some cases, automatic conversion between modes is performed as indicated<br />

above, although information may be lost as in the case of real to integer conversion, where the<br />

fractional value may no longer be represented. Be aware of such implied conversions and their effect<br />

on program behavior.<br />

One particular potential source of error, however, is the attempted assignment of variable values<br />

read from input data to variables defined with conflicting internal representation. Specifically, a<br />

data field containing a noninteger format number should not be assigned to an integer variable<br />

in a read statement. This will result in loss of information and is therefore treated as an error condition.<br />

Table 2-2 specifies the actions taken when different combinations of data and variable definitions<br />

occur.<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!