1.4 Comparison Including Error

Since floating-point numbers are approximated in computer processing, they will always contain some error. For example, in the program,

      LOGICAL LEQ

      X = 1.

      Y = X/3.

      LEQ = X .EQ. (Y*3.)

leq will not be .true.. However, since both x and Y are approximate values,  it is rational to make approximate comparison of these values when comparing them, and in many instances, this is what the user wishes to do. In other words, in most cases, what is important is that the values x and y*3. are approximately the same, and not that they are exactly the same.

The  LRLLIB can be used for such calculations. For example, 

      LOGICAL LEQ, lreq



      X = 1.

      Y = X/3.

      NumRu::DCL.gllset(cp,lpara)

      LEQ = return_value = NumRu::DCL.lreq(x,y)



will enable approximate comparisons. lreq is a function of  LRLLIB, and is used to check whether 2 values coincide approximately within the precision of a calculator. The precision of the calculator is the product of the internal variable 'repsl' managed by glpget/glpset and the 'rfact'. 'REPSL' is  set as the actual precision of internal representation of the floating-point number multiplied by the safety factor of 10, and the initial value of 'RFACT' is set at 1.  'REPSL' is set upon installation of the library, and it cannot be changed in the programming. However, if the precision of the calculator is poor and a rougher comparison needs to be made, the internal variable 'RFACT' should be set to a value larger than 1.

Several sub-packages besides the LRLLIB in MATH1 are equipped with similar functions.