Determines if two REAL(wp) numbers are equal up to a specified tolerance (=PP_RealTolerance, normaly set to machine precision) Takes into account that x,y are located in-between [-1;1] Based on Algorithm 139, Kopriva
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x |
(IN) first scalar to be compared |
||
| real(kind=wp), | intent(in) | :: | y |
(IN) second scalar to be compared |
(OUT) TRUE if |x-y| < 2*PP_RealTolerance
FUNCTION ALMOSTEQUAL(x,y) IMPLICIT NONE !---------------------------------------------------------------------------------------------------------------------------------- ! INPUT/OUTPUT VARIABLES REAL(wp),INTENT(IN) :: x !! (IN) first scalar to be compared REAL(wp),INTENT(IN) :: y !! (IN) second scalar to be compared LOGICAL :: AlmostEqual !! (OUT) TRUE if |x-y| < 2*PP_RealTolerance !---------------------------------------------------------------------------------------------------------------------------------- ! LOCAL VARIABLES !================================================================================================================================== AlmostEqual=.FALSE. IF((x.EQ.0.0_wp).OR.(y.EQ.0.0_wp)) THEN IF(ABS(x-y).LE.2.0_wp*PP_RealTolerance) AlmostEqual=.TRUE. ELSE ! x, y not zero IF((ABS(x-y).LE.PP_RealTolerance*ABS(x)).AND.((ABS(x-y).LE.PP_RealTolerance*ABS(y)))) AlmostEqual=.TRUE. END IF ! x,y zero END FUNCTION ALMOSTEQUAL