introduced (in)equality comparison for double precision

This commit is contained in:
Martin Diehl 2016-03-05 21:37:22 +01:00
parent 75480bc677
commit 83ccd7c982
1 changed files with 28 additions and 2 deletions

View File

@ -172,9 +172,9 @@ end subroutine prec_init
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief figures out if a floating point number is NaN !> @brief figures out if a floating point number is NaN
! basically just a small wrapper, because gfortran < 4.9 does not have the IEEE module ! basically just a small wrapper, because gfortran < 5.0 does not have the IEEE module
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
logical elemental function prec_isNaN(a) logical elemental pure function prec_isNaN(a)
implicit none implicit none
real(pReal), intent(in) :: a real(pReal), intent(in) :: a
@ -187,4 +187,30 @@ logical elemental function prec_isNaN(a)
#endif #endif
end function prec_isNaN end function prec_isNaN
!--------------------------------------------------------------------------------------------------
!> @brief equality comparison for double precision
! replaces "==" but for certain (absolute) tolerance. Counterpart to dNeq
!--------------------------------------------------------------------------------------------------
logical elemental pure function dEq(a,b,tol)
real(pReal), intent(in) :: a,b
real(pReal), intent(in), optional :: tol
real(pReal), parameter :: eps = 1.0e-15_pReal
dEq = merge(.True., .False.,abs(a-b) < merge(tol,eps,present(tol)))
end function dEq
!--------------------------------------------------------------------------------------------------
!> @brief inequality comparison for double precision
! replaces "!=" but for certain (absolute) tolerance. Counterpart to dEq
!--------------------------------------------------------------------------------------------------
logical elemental pure function dNeq(a,b,tol)
real(pReal), intent(in) :: a,b
real(pReal), intent(in), optional :: tol
real(pReal), parameter :: eps = 1.0e-15_pReal
dNeq = merge(.True., .False.,abs(a-b) < merge(tol,eps,present(tol)))
end function dNeq
end module prec end module prec