[Info-vax] VMS Software Q1 '23 Update

Arne Vajhøj arne at vajhoej.dk
Sat Jan 28 09:23:05 EST 2023


On 1/27/2023 7:45 PM, Arne Vajhøj wrote:
> In some contexts the relative difference may be better than the
> absolute difference:
> 
> IF Math.Abs(x / y - 1.0) < 0.001 THEN

25 years ago I liked this one:

const double FP_SMALL = 0.000001;
const double FP_ABS_SMALL_1 = -FP_SMALL;
const double FP_ABS_SMALL_2 =  FP_SMALL;
const double FP_REL_SMALL_1 = 1-FP_SMALL;
const double FP_REL_SMALL_2 = 1+FP_SMALL;

BOOL num_eq(double x1,double x2)
{
    double d;
    if((-1<x2)&&(x2<1)) {
       d = x1 - x2;
       return ((FP_ABS_SMALL_1<d)&&(d<FP_ABS_SMALL_2));
    } else {
       d = x1 / x2;
       return ((FP_REL_SMALL_1<d)&&(d<FP_REL_SMALL_2));
    }
}

Apparently I did not like space around operators back then.

Arne




More information about the Info-vax mailing list