[UP]


Manual Reference Pages  - in_margin (3)

NAME

in_margin(3f) - [M_math] check if two reals are approximately equal using a relative margin

CONTENTS

Synopsis
Description
Options
Example

SYNOPSIS

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

DESCRIPTION

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.

OPTIONS

expected_value
  First value
measured_value
  Second value
allowed_margin
  Allowed relative margin

EXAMPLE

Sample program:

   program demo_in_margin
   use :: M_math, 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)

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

Results:

    F

    F

    F

    F

    F F F F F

    F F F F T

    T

    T

    T

    T


in_margin (3) October 17, 2020
Generated by manServer 1.08 from d0af7456-b440-491c-a555-ba3aef0d77c3 using man macros.