in_margin(3f) - [M_verify] check if two reals are approximately equal using a relative margin
Synopsis
Description
Options
Examples
elemental pure function in_margin( expected_value, measured_value, allowed_margin )
real, intent(in) :: expected_value real, intent(in) :: measured_value real, intent(in) :: allowed_margin class(*),intent(in) :: invalue
Compare two values to see if they are relatively equal using the specified allowed margin. That is, see if VALUE_MEASURED is in the range VALUE_EXPECTED +- ALLOWED_ERROR where the allowed error varies with the magnitude of the values, such that the allowed error is margin * average magnitude of measured and expected).So the allowed error is smaller when the magnitudes are smaller.
expected_value First value measured_value Second value allowed_margin Allowed relative margin
Sample program:
program demo_in_margin use :: M_verify, only : in_margin implicit none write(*,*) in_margin(4.00000,3.99999,0.000000001) write(*,*) in_margin(4.00000,3.99999,0.00000001) write(*,*) in_margin(4.00000,3.99999,0.0000001) write(*,*) in_margin(4.00000,3.99999,0.000001)Results:write(*,*) in_margin([4.0,40.0,400.0,4000.0,40000.0], [3.9,39.9,399.9,3999.9,39999.9] ,0.000001) write(*,*) in_margin([4.0,40.0,400.0,4000.0,40000.0], [3.9,39.9,399.9,3999.9,39999.9] ,0.00001)
write(*,*) in_margin(4.00000,3.99999,0.00001) write(*,*) in_margin(4.00000,3.99999,0.0001) write(*,*) in_margin(4.00000,3.99999,0.001) write(*,*) in_margin(4.00000,3.99999,0.01)
end program demo_in_margin
Nemo Release 3.1 | in_margin (3) | February 23, 2025 |