INT2(A) (IBM extension)

Purpose

Converts a real or integer value into a two byte integer.

Class

Elemental function

Argument type and attributes

A
An INTENT(IN) INTEGER or REAL

INT2 cannot be passed as an actual argument of another function call.

Result type and attributes

INTEGER(2) scalar

Result value

If A is of type integer, INT2(A) = A.

If A is of type real, there are two possibilities:
  • If |A| < 1, INT2(A) has the value 0
  • If |A| >= 1, INT2(A) is the integer whose magnitude is the largest integer that does not exceed the magnitude of A, and whose sign is the same as the sign of A.

In both cases, truncation may occur.

Examples

The following is an example of the INT2 function.

    REAL*4 :: R4
    REAL*8 :: R8
    INTEGER*4 :: I4
    INTEGER*8 :: I8

    R4 = 8.8; R8 = 18.9
    I4 = 4; I8 = 8
    PRINT *, INT2(R4), INT2(R8), INT2(I4), INT2(I8)
    PRINT *, INT2(2.3), INT2(6)
    PRINT *, INT2(65535.78), INT2(65536.89)
    END

The following is sample output generated by the program above:

    8 18 4 8
    2 6
    -1 0     ! The results indicate that truncation has occurred, since
             ! only the last two bytes were saved.