[Cuis-dev] testing Float results

ken.dickey at whidbey.com ken.dickey at whidbey.com
Tue Jun 4 07:39:25 PDT 2024


On 2024-06-03 16:36, Mark Volkmann via Cuis-dev wrote:

> Is there a function that tests whether two Float values are "close" 
> (within some delta)?

Really, it depends on what you expect to use numbers for.

Numerical methods using Floats are frequently unstable and "the wrong 
answer fast".

   https://people.cs.pitt.edu/~cho/cs1541/current/handouts/goldberg.pdf

Various strategies have been devised to make numerical calculations more 
robust.

One simple idea, used in several systems such as Mathematica, is to keep 
the highest and lowest possible values a function computes and carry the 
calculation of values throughout a calculation.  You then expect the 
"exact" value to be within this interval.

   https://en.wikipedia.org/wiki/Interval_arithmetic

If the interval is small, you may have a high confidence in a close 
result.  If the "answer" is a humongous interval, you better do the 
error analysis.

An interesting variant of this is Ball Arithmetic, where the answer is 
not an interval but lives within a (potentially multidimensional) 
hypersphere.

   https://www.texmacs.org/joris/ball/ball.html

NB: I am not mathematician enough to evaluate Ball Arithmetic.

I have used Interval Arithmetic for some cases.  Interestingly, there 
was an Apple function grapher which used Interval Arithmetic to 
automatically calculate function values to the required precision.  This 
meant that you could look at f(x) = x * sin(x) near zero, and keep 
"inzooming" to smaller and smaller ranges and still see an accurate 
graph of this "squiggle function".

There are some very interesting discussions about real numbers -- and 
holes between them -- in Lakoff & Nunez's _Where Mathematics Comes From_

HTH,
-KenD


More information about the Cuis-dev mailing list