[Cuis-dev] testing Float results
Andres Valloud
ten at smallinteger.com
Mon Jun 3 23:34:49 PDT 2024
Indeed, it all depends on what is being done. Sometimes a few ulps off
is fine (because numerical analysis often cannot guarantee exact results
for arbitrary inputs), and some other times even one ulp off is
definitely wrong.
On 6/3/24 8:46 PM, Martin McClure via Cuis-dev 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.
>>>
>
More information about the Cuis-dev
mailing list