Next: Integer Division
Up: Mixing Objects of Different
Previous: Mixed Type Numeric Expressions
Problems often occur with mixed-type arithmetic; the rules for type
conversion are given below.
- LHS INTEGER; RHS REAL or DOUBLE PRECISION -- the RHS is
evaluated, truncated (all the decimal places lopped off) then
assigned to the LHS.
- LHS REAL or DOUBLE PRECISION; RHS INTEGER -- the RHS is coerced and stored
(approximately) in the LHS.
For example,
REAL a, b; INTEGER i, j
a = 3.0; b = 4.0
i = b - a
j = -0.9
a = j
-
b - a would be around 1.0; due to truncation
i would be 0 or 1.
- j would be truncated to 0.
- a would be set to (about) 0.000.
For more information, click here
Next: Integer Division
Up: Mixing Objects of Different
Previous: Mixed Type Numeric Expressions
Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 18:56:08 GMT 1996Not for commercial use.