anchor.diff:  ! https://www.python.org/dev/peps/pep-0485/#proposed-implementation
   ! https://github.com/PythonCHB/close_pep/blob/master/is_close.py
   
  -  real(wp), intent(in) :: actual, desired
  -  real(wp), intent(in), optional :: rtol, atol
  -  logical, intent(in), optional :: equal_nan
  +real(sp), intent(in) :: actual, desired
  +real(sp), intent(in), optional :: rtol, atol
  +logical, intent(in), optional :: equal_nan
   
  -  real(wp) :: r,a
  -  logical :: n
  -  ! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
  -  r = 1e-5_wp
  -  a = 0._wp
  -  n = .false.
  -  if (present(rtol)) r = rtol
  -  if (present(atol)) a = atol
  -  if (present(equal_nan)) n = equal_nan
  +real(sp) :: r,a
  +logical :: n
  +! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
  +r = 1e-5_sp
  +a = 0
  +n = .false.
  +if (present(rtol)) r = rtol
  +if (present(atol)) a = atol
  +if (present(equal_nan)) n = equal_nan
   
  -  !print*,r,a,n,actual,desired
  +!print*,r,a,n,actual,desired
   
   !--- sanity check
  -  if ((r < 0._wp).or.(a < 0._wp)) error stop "impossible tolerance"
  -!--- simplest case -- too unlikely, especially for arrays?
  -  !isclose = (actual == desired)
  -  !if (isclose) return
  +if ((r < 0).or.(a < 0)) error stop 'invalid tolerance parameter(s)'
   !--- equal nan
  -  isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
  -  if (isclose) return
  -!--- Inf /= -Inf, unequal NaN
  -  if (.not.ieee_is_finite(actual) .or. .not.ieee_is_finite(desired)) return
  +isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
  +if (isclose) return
  +!--- Inf /= Inf, unequal NaN
  +if (.not.ieee_is_finite(actual) .or. .not.ieee_is_finite(desired)) return
   !--- floating point closeness check
  -  isclose = abs(actual-desired) <= max(r * max(abs(actual), abs(desired)), a)
  +isclose = abs(actual-desired) <= max(r * max(abs(actual), abs(desired)), a)
   
  -end function isclose
  +end function isclose_32
   
   
  -impure elemental subroutine assert_isclose(actual, desired, rtol, atol, equal_nan, err_msg)
  -! NOTE: with Fortran 2018 this can be Pure
  +elemental logical function isclose_64(actual, desired, rtol, atol, equal_nan) result (isclose)
  +! inputs
  +! ------
  +! actual: value "measured"
  +! desired: value "wanted"
  +! rtol: relative tolerance
  +! atol: absolute tolerance
  +! equal_nan: consider NaN to be equal?
   !
  +!  rtol overrides atol when both are specified
  +!
  +! https://www.python.org/dev/peps/pep-0485/#proposed-implementation
  +! https://github.com/PythonCHB/close_pep/blob/master/is_close.py
  +
  +real(dp), intent(in) :: actual, desired
  +real(dp), intent(in), optional :: rtol, atol
  +logical, intent(in), optional :: equal_nan
  +
  +real(dp) :: r,a
  +logical :: n
  +! this is appropriate INSTEAD OF merge(), since non present values aren't defined.
  +r = 1e-5_dp
  +a = 0
  +n = .false.
  +if (present(rtol)) r = rtol
  +if (present(atol)) a = atol
  +if (present(equal_nan)) n = equal_nan
  +
  +!print*,r,a,n,actual,desired
  +
  +!--- sanity check
  +if ((r < 0).or.(a < 0)) error stop 'invalid tolerance parameter(s)'
  +!--- equal nan
  +isclose = n.and.(ieee_is_nan(actual).and.ieee_is_nan(desired))
  +if (isclose) return
  +!--- Inf /= Inf, unequal NaN
  +if (.not.ieee_is_finite(actual) .or. .not.ieee_is_finite(desired)) return
  +!--- floating point closeness check
  +isclose = abs(actual-desired) <= max(r * max(abs(actual), abs(desired)), a)
  +
  +end function isclose_64
  +
  +
  +impure elemental subroutine assert_isclose_64(actual, desired, rtol, atol, equal_nan, err_msg)
   ! inputs
   ! ------
   ! actual: value "measured"
  
positive.code: !
  ! rtol overrides atol when both are specified
  
    real(wp), intent(in) :: actual, desired
    real(wp), intent(in), optional :: rtol, atol
    logical, intent(in), optional :: equal_nan
    character(*), intent(in), optional :: err_msg
  
    if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
      write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
      error stop "values not within specified tolerances"
    endif
  
  end subroutine assert_isclose
  
  end module assert
  
  
negative.code: module assert
  
  use, intrinsic:: iso_fortran_env, only: sp=>real32, dp=>real64, stderr=>error_unit
  use, intrinsic:: ieee_arithmetic
  
  implicit none (type, external)
  private
  public :: isclose, assert_isclose
  
  interface isclose
  module procedure isclose_32, isclose_64
  end interface isclose
  
  interface assert_isclose
  module procedure assert_isclose_32, assert_isclose_64
  end interface assert_isclose
  
  contains
  
  elemental logical function isclose_32(actual, desired, rtol, atol, equal_nan) result (isclose)
  ! inputs
  ! ------
  ! actual: value "measured"
  