Solution for exercise 02

Review

  1. The float data type in Fortran is called REAL, while INTEGER and DOUBLE PRECISION (or DOUBLEPRECISION w/o blank) exist in Fortran.
  2. Youd should always use IMPLICIT NONE.

Task 1 - Integer numbers

Normal INTEGER has KIND=4, so 32 Bit, meaning that 2147483647 + 1 will result in the most negative value -2147483648.:
      PROGRAM kindint

      INTEGER (KIND=4)  k
      k = 2147483647
      WRITE(*,*) K, k+1
      STOP
      END
  

Task 2 - Not a Number

Example:

test_real.f

  1. For x = 0 the result of 1/x is Infinity, for x = -1 the result of sqrt(x) is NaN.
  2. For x = -1 the code of gfortran throws a floating point exception, meaning that it will abort further execution. The ifort compiler's program will also throw a floating point exception for x = 0 if one enable it with -fpe0