Are two numbers almost equal
Uses the same predicate as numpy's isclose
:
abs(a - b) <= (atol + rtol * abs(b))
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=real128), | intent(in) | :: | a | |||
real(kind=real128), | intent(in) | :: | b | |||
real(kind=real128), | intent(in), | optional | :: | rtol | ||
real(kind=real128), | intent(in), | optional | :: | atol |
logical elemental function almost_equal_r128(a, b, rtol, atol)
use optionals, only: get_option_with_default
real(real128), intent(in) :: a, b
real(real128), intent(in), optional :: rtol
real(real128), intent(in), optional :: atol
real(real128) :: rtol_val, atol_val
rtol_val = get_option_with_default(rtol, 1e-5_real128)
atol_val = get_option_with_default(atol, 1e-8_real128)
almost_equal_r128 = (abs(a - b) <= (atol_val + (rtol_val * abs(b))))
end function almost_equal_r128