fp equality

Doug Gwyn (ACISD/MCSB) uunet!BRL.MIL!gwyn
Fri Dec 10 13:58:32 PST 1993


I can't dispute the efficiency issue, but I personally would still
seek inherently robust computations wherever possible.  In the case
of your example
	if (x == y)
		z = fprime(x) ;
	else
		z = (f(x)-f(y))/(x-y) ;
if x and y have nearly the same value, (x-y) is computed with poor
precision, and the result z could be wildly off the theoretical value.
So I'd very likely code this to always invoke the fprime() function, or
some other rearrangement of the computation to obtain an accurate result
no matter what reasonable values x and y happen to have.
In the case of singularities, usually I've found that computations
trying to evaluate at or very near the mathematical singular point
can be replaced with other computations that are more robust in those
regions.  E.g. a function of x that is singular at x==0 might have a
related function (1/f for example) that is regular at x==0, so one
might use one branch of computation for all x<=1 and another formula
for x>1.  The details of course depend on the application..
Testing for exact equality to a singular point won't do much good when
the singularity occurs at a mathematical value that is not exactly
representable.  That's not a problem for x==0, x==-1, etc. but is
germane when the singularity occurs at Pi, 1/e, etc.
There may be some computations that simply cannot be rephrased to
produce accurate answers across the whole domain, but I don't recall
having encountered such cases in the applications I've worked on.



More information about the Numeric-interest mailing list