eq Interface

public interface eq

Tests two real numberes for equality using a tolerance if provided by the user, or selecting a tolerance automatically otherwise.

Syntax

 n = eq(f1, f2, eps)

Where:

  • f1: First real number to compare for equality.
  • f2: Second real to compare for equality.
  • eps: User selected tolerance for the comparison. If not provided it will be selected automatically.

It returns True both numbers are equal according to the selected tolerance and False otherwise

Example

The following program tests if two real numbers are equal:

 PROGRAM eqExample
    USE FU_Numbers, ONLY: eq
    IMPLICIT NONE
    WRITE(*,*) eq(5., 5.00001, 0.000000001)
    WRITE(*,*) eq(5., 5.00001, 0.001)
    WRITE(*,*) eq(5., 5.00001)
 END PROGRAM eqExample

Contents


Module Procedures

private elemental function eq_sp(x1, x2, eps) result(res)

Arguments

Type IntentOptional Attributes Name
real(kind=sp), intent(in) :: x1

First real value to compare for equality.

real(kind=sp), intent(in) :: x2

Second real value to compare for equality.

real(kind=sp), intent(in), optional :: eps

User selected tolerance for the comparison. If not provided it will be selected automatically.

Return Value logical

True if both numbers are equal according to the selected tolerance. False otherwise.

private elemental function eq_dp(x1, x2, eps) result(res)

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: x1

First real value to compare for equality.

real(kind=dp), intent(in) :: x2

Second real value to compare for equality.

real(kind=dp), intent(in), optional :: eps

User selected tolerance for the comparison. If not provided it will be selected automatically.

Return Value logical

True if both numbers are equal according to the selected tolerance. False otherwise.

private elemental function eq_qp(x1, x2, eps) result(res)

Arguments

Type IntentOptional Attributes Name
real(kind=qp), intent(in) :: x1

First real value to compare for equality.

real(kind=qp), intent(in) :: x2

Second real value to compare for equality.

real(kind=qp), intent(in), optional :: eps

User selected tolerance for the comparison. If not provided it will be selected automatically.

Return Value logical

True if both numbers are equal according to the selected tolerance. False otherwise.