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.

      CALL GLLSET('LEPSL', .TRUE.)

      LEQ = LREQ(X, Y*3.)



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.