[Cuis-dev] testing Float results

Mark Volkmann r.mark.volkmann at gmail.com
Tue Jun 4 12:06:08 PDT 2024


How do you feel about using "approximately equal" tests for things like
unit tests for the calculation of areas of 2D shapes such as circles?

On Mon, Jun 3, 2024 at 10:47 PM Martin McClure via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hi Mark,
>
> Welcome to the list -- good to see you diving into Cuis!
>
> As Andres says, there are messages to do this kind of test on Floats.
>
> I find myself compelled, however, to warn about using such
> "approximately equal" tests when inappropriate. I recently discovered
> this kind of usage in an ancient test framework, and it was allowing
> tests to pass that should not have. Those tests are being replaced with
> equality tests.
>
> As I commented to a co-worker just this morning, accepting as correct a
> Float result that is one ULP different from the correct Float is really
> no different than accepting 5 as a correct answer to 2 + 2.
>
> There are, of course, times when figuring out the exact rounding
> expected in a sequence of floating-point operations is impractical, and
> accepting a certain amount of cumulative error is OK. Floats are often
> used in applications where accuracy is only required to some specific
> precision, but it's also good to keep in mind that each Float precisely
> represents one value, and each operation on a Float has only one correct
> answer.
>
> Regards,
> -Martin
>
> On 6/3/24 19:49, Andres Valloud via Cuis-dev wrote:
> > Look at Float>>isWithin:floatsFrom:, and see also Float>>ulp.
> >
> > On 6/3/24 4:36 PM, Mark Volkmann via Cuis-dev wrote:
> >> Is there a function that tests whether two Float values are "close"
> >> (within some delta)?
> >> I can write it, but I thought that might be provided.
> >> I looked at all the methods in the Float class, but didn't find one
> >> like that.
> >>
> >> --
> >> R. Mark Volkmann
> >> Object Computing, Inc.
> >>
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>


-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240604/1dffba07/attachment.htm>


More information about the Cuis-dev mailing list