SPL to HP C/XL Migration Guide (30231-90001)
5- 18
| 4. addition | |
| subtraction | |
| | |
---------------------------------------------------------------------------------------------
In general, well-formed expressions, with parentheses used to avoid
possible confusion, will always yield the same sequence of operations.
Care may be necessary to maintain the same precision, because of implic-
it data conversion. (See "Type Mixing (Arithmetic)" in this chapter).
Type Mixing (Arithmetic)
Table 5-21. Arithmetic Type Mixing
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| The mixing of data types across operands is | Arithmetic data types may be mixed. HP |
| not allowed in SPL, except that real and | C/XL performs automatic type conversions as |
| long values may be exponentiated to integer | needed, generally proceeding toward long |
| powers. | int and double values. Many type transfer |
| | functions can be eliminated or simplified. |
| Type transfer functions (see "Expression | |
| Types" above) are used to convert data | |
| types. | Where data types need forcing, HP C/XL |
| | provides the "cast" operators--data type |
| | names in parentheses preceding the value to |
| | be converted. See "Expression Types" above |
| | for more detail. |
| | |
---------------------------------------------------------------------------------------------
As an example, if you need to force a floating point divide of two
integers, the cast operator is (float):
X = (float)M/(float)N;
Cast operators are essential for converting exponentiation involving
integers into the pow function. The SPL statement:
I := J^K;
all integer variables
becomes the HP C/XL statement:
I = pow ( (double) J , (double) K ) ;