almost_equal_real32 Function

private pure elemental function almost_equal_real32(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)

Uses

  • proc~~almost_equal_real32~~UsesGraph proc~almost_equal_real32 almost_equal_real32 iso_fortran_env iso_fortran_env proc~almost_equal_real32->iso_fortran_env

Test a and b for approximate equality, where a and b are both reals. (KCW, 2024-05-25)

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: a
real(kind=real32), intent(in) :: b
real(kind=real32), intent(in), optional :: absolute_tolerance
real(kind=real32), intent(in), optional :: relative_tolerance

Return Value logical


Called by

proc~~almost_equal_real32~~CalledByGraph proc~almost_equal_real32 almost_equal_real32 interface~almost_equal almost_equal interface~almost_equal->proc~almost_equal_real32 proc~almost_divisible_real32 almost_divisible_real32 proc~almost_divisible_real32->interface~almost_equal proc~almost_divisible_real64 almost_divisible_real64 proc~almost_divisible_real64->interface~almost_equal interface~almost_divisible almost_divisible interface~almost_divisible->proc~almost_divisible_real32 interface~almost_divisible->proc~almost_divisible_real64 proc~dyn_mpas_init_phase4 mpas_dynamical_core_type%dyn_mpas_init_phase4 proc~dyn_mpas_init_phase4->interface~almost_divisible proc~dyn_init dyn_init proc~dyn_init->proc~dyn_mpas_init_phase4 interface~dyn_init dyn_init interface~dyn_init->proc~dyn_init

Variables

Type Visibility Attributes Name Initial
real(kind=real32), private :: error_tolerance

Source Code

    pure elemental function almost_equal_real32(a, b, absolute_tolerance, relative_tolerance) result(almost_equal)
        use, intrinsic :: iso_fortran_env, only: real32

        real(real32), intent(in) :: a, b
        real(real32), optional, intent(in) :: absolute_tolerance, relative_tolerance
        logical :: almost_equal

        real(real32) :: error_tolerance

        if (present(relative_tolerance)) then
            error_tolerance = relative_tolerance * max(abs(a), abs(b))
        else
            error_tolerance = epsilon(1.0_real32) * max(abs(a), abs(b))
        end if

        if (present(absolute_tolerance)) then
            error_tolerance = max(absolute_tolerance, error_tolerance)
        end if

        if (abs(a - b) <= error_tolerance) then
            almost_equal = .true.

            return
        end if

        almost_equal = .false.
    end function almost_equal_real32