! If the norm is computed as an Inf or a NaN then there may
! be Infs or NaNs in the input data or the input vector contained
! all valid, finite, floating point numbers and the result was
! too large to represent in the available precision. 
!
! There are four different situations to deal with
!
! 1. Input contains both Inf and NaN values: 
!    Result = +Inf; set flags: inexact = F
! 2. Input contains Inf values but no NaN values:
!    Result = +Inf; set flags: inexact = F, overflow = F
! 3. Input contains NaN values but no Inf values:
!    Result = qNaN; set flags: inexact = F, invalid = T
! 4. Input contains all valid, finite, floating 
!    point values but the final result is not storable
!    in the available precision:
!    Result = +Inf; set flags: inexact = T, overflow = T
!
! The logical variable infInInput is used to distinguish 
! between Cases 1, 2 (infInInput = T) and 4 (infInInput = F)
! above.
!
! The inexact flag may signal as a result of a finite
! calculation.
!
! NOTE: the underflow flag can not signal as a result of
!       using Kahan's algorithm.
!
! The only IEEE status flags set at this point are those which
! need to be communicated to the calling procedure. These
! will be added to those that were signalling on entry.
! This happens automatically and does not require any
! explicit coding here.

    IF (ieee_is_nan(y)) THEN
! Result = qNaN (Case 3 above), inexact should be false
! and invalid should signal.
      CALL ieee_set_flag(ieee_inexact, .FALSE.)
      CALL ieee_set_flag(ieee_invalid, .TRUE.)
    ELSE IF (.NOT. ieee_is_finite(y)) THEN
! Result is +Inf (Cases 1, 2 and 4) above
      CALL ieee_set_flag(ieee_overflow, .NOT. infInInput)
      CALL ieee_set_flag(ieee_inexact, .NOT. infInInput)
    END IF

! Finally restore the current IEEE halting mode flags
! back to what it was on entry to the routine.
    CALL ieee_set_halting_mode(ieee_all, haltingFlags)
