<div dir="ltr">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?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 3, 2024 at 10:47 PM Martin McClure via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Mark,<br>
<br>
Welcome to the list -- good to see you diving into Cuis!<br>
<br>
As Andres says, there are messages to do this kind of test on Floats.<br>
<br>
I find myself compelled, however, to warn about using such <br>
"approximately equal" tests when inappropriate. I recently discovered <br>
this kind of usage in an ancient test framework, and it was allowing <br>
tests to pass that should not have. Those tests are being replaced with <br>
equality tests.<br>
<br>
As I commented to a co-worker just this morning, accepting as correct a <br>
Float result that is one ULP different from the correct Float is really <br>
no different than accepting 5 as a correct answer to 2 + 2.<br>
<br>
There are, of course, times when figuring out the exact rounding <br>
expected in a sequence of floating-point operations is impractical, and <br>
accepting a certain amount of cumulative error is OK. Floats are often <br>
used in applications where accuracy is only required to some specific <br>
precision, but it's also good to keep in mind that each Float precisely <br>
represents one value, and each operation on a Float has only one correct <br>
answer.<br>
<br>
Regards,<br>
-Martin<br>
<br>
On 6/3/24 19:49, Andres Valloud via Cuis-dev wrote:<br>
> Look at Float>>isWithin:floatsFrom:, and see also Float>>ulp.<br>
><br>
> On 6/3/24 4:36 PM, Mark Volkmann via Cuis-dev wrote:<br>
>> Is there a function that tests whether two Float values are "close" <br>
>> (within some delta)?<br>
>> I can write it, but I thought that might be provided.<br>
>> I looked at all the methods in the Float class, but didn't find one <br>
>> like that.<br>
>><br>
>> -- <br>
>> R. Mark Volkmann<br>
>> Object Computing, Inc.<br>
>><br>
<br>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif">R. Mark Volkmann</font></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">Object Computing, Inc.</font></span></div></div></div></div></div></div></div></div>