module Auxiliar

contains

  ! ************************************************************************
  ! ************************************************************************

  logical function isInteger(a)

    use Constants

    implicit none

    ! This function verifies if the real argument 'a' is integer, i.e.,
    ! if "a = floor(a)". Return 'true' if the value of 'a' is integer,
    ! and 'false' otherwise.

    ! SCALAR ARGUMENT
    real(kind=8), intent(in) :: a

    if(abs(a) .le. EPSILON_INT) then

       ! a is equal to zero.
       isInteger = .true.
       return
    
    else if(min(abs(a - real(floor(a), kind=8)),     &
                abs(a - real(ceiling(a), kind=8))) / &
            max(1.0d0, abs(a)) .le. EPSILON_INT) then

       isInteger = .true.
       return

    end if

    isInteger = .false.
    return

  end function isInteger

  ! ************************************************************************
  ! ************************************************************************

  logical function isBinary(a)

    use Constants

    implicit none

    ! This function verifies if the real argument is 0 or 1. Return 'true'
    ! if a = 0 or a = 1, and 'false' otherwise.

    ! SCALAR ARGUMENT
    real(kind=8), intent(in) :: a

    if(abs(a) .le. EPSILON_INT) then

       isBinary = .true.
       return

    end if

    if(a .ge. 1.0d0 - EPSILON_INT .and. a .le. 1.0d0 + EPSILON_INT) then

       isBinary = .true.
       return

    end if

    isBinary = .false.
    return

  end function isBinary

end module Auxiliar
