next up previous contents
Next: Expression Evaluation Up: Parameterised Intrinsic Types Previous: Real KIND Selection

 

Kind Functions

It is often useful to be able to interrogate an object to see what kind parameter it has.

KIND is an intrinsic function that returns the integer which corresponds to the KIND of the argument. The argument can be a variable or a literal. For example, KIND(a) will return the integer which corresponds to the kind of a and KIND(20) returns the kind value chosen for the representation used for the default integer type.

The type conversion functions, INT, NINT, REAL, DBLE, etc., have an optional KIND= argument for specifying the representation of the result of the function, for example,

    INTEGER(KIND=6) :: ik6
    REAL x
    INTEGER i
     ...
    ik6 = REAL(x,KIND=6)
     ! or better
    ik6 = REAL(x,KIND(ik6))

Retaining the representation precision is important, note the difference between the following two assignments,

    INTEGER ia, ib
    REAL(KIND=6) rk6
     ...
    rk6 = rk6 + REAL(ia,KIND=6)/REAL(ib,KIND=6)

and,

    rk6 = rk6 + REAL(ia)/REAL(ib)

In the second example, the RHS operand is less accurate than in the first.

Now try this question gif

Return to corresponding overview page gif


next up previous contents
Next: Expression Evaluation Up: Parameterised Intrinsic Types Previous: Real KIND Selection

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