next up previous contents
Next: Mixed Type Assignment Up: Mixing Objects of Different Previous: Mixing Objects of Different

 

Mixed Numeric Type Expressions

When an (sub)expression is evaluated, the actual calculation in the CPU must be between operands of the same type, this means if the expression is of mixed type, the compiler must automatically convert (promote or coerce) one type to another. Default types have an implied ordering

  1. INTEGER -- lowest
  2. REAL
  3. DOUBLE PRECISION
  4. COMPLEX -- highest

thus if an INTEGER is mixed with a REAL the INTEGER is promoted to a REAL and then the calculation performed; the resultant expression is of type REAL.

For example,

Consider the expression,

    int*real*dp*c

the types are coerced as follows:

  1. int to REAL
  2. int*real to DOUBLE PRECISION
  3. (int*real)*dp to COMPLEX.

The above expression is therefore COMPLEX valued.

Note that numeric and non-numeric types cannot be mixed using intrinsic operators, nor can LOGICAL and CHARACTER.

In general one must think hard and long about mixed mode arithmetic!

Return to corresponding overview page gif


next up previous contents
Next: Mixed Type Assignment Up: Mixing Objects of Different Previous: Mixing Objects of Different

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.