P
Ich werd langsam alt, habe gerade was von mir gefunden, ist heute noch im Einsatz.
/***********************************************************************.FA*
.FUNCTION [ floatcomp ]
--------------------------------------------------------------------------
.GROUP [ GenUtil ]
.AUTHOR [ PAD ]
--------------------------------------------------------------------------
.DESCRIPTION
comparing two float values for equality
two float values are equal if they are in an intervall
of [(-0.25e-12 * max(a,b))..(+0.25e-12(max(a,b))]
--------------------------------------------------------------------------
.INDEX
Utilities
--------------------------------------------------------------------------
.PARAMETER
IN long double a these two variables get compared
long double b
--------------------------------------------------------------------------
.RETURNVALUE
0 equal within limits
1 notequal within limits
--------------------------------------------------------------------------
.VARIABLE_REFERENCES
--------------------------------------------------------------------------
.HISTORY
Date Author Comment
09.05.89 PAD comments adapted for SOFTDOC
16.07.89 PAD Empfindlichkeit von e-14 nach
e-12 verringert
**********************************************************************.HE**/
//#define FEQU(a,b) floatcomp((long double)(a),(long double)(b))
//#define FNEQU(a,b) (!floatcomp((long double)(a),(long double)(b)))
//#define TESTMAIN
int floatcomp(double a, double b)
{
double fuzz = 0.5e-12L;
double c,d;
c=fabs((double)(a-b));
d=(fuzz * max(fabs((double) a),fabs((double)b)));
if (c <= d)
return PASS;
else return FAIL;
}
#ifdef TESTMAIN
main()
{
long double f = 0L;
while (FEQU(1,f))
{
printf ("%.30Lf, %.30Lf\n",f,(long double)f);
f+= 0.1L;
}
f=0.0L;
while (FNEQU(0,f))
{
printf ("%.30Lf, %.30Lf\n",f,(long double)f);
f+= 0.1L;
}
return 0;
}
#endif