Re: New version of John Hayes' tester
- From: "David N. Williams" <williams@xxxxxxxxx>
- Date: Thu, 16 Aug 2007 14:16:48 GMT
Krishna Myneni wrote:
> Krishna Myneni wrote:
>> Anton Ertl wrote:
>
>>> Concerning the fine-tuning, I meant the REL-NEAR and ABS-NEAR stuff;
>>> with FSENSITIVITY you can do either relative (negative FSENSITIVITY)
>>> or absolute (positive FSENSITIVITY) approximate comparison, but not
>>> both at once. Do you use that?
>>
>> When a nearness comparison is made, ftester does both absolute nearness
>> ("FABS=") and relative nearness ("FREL=") comparsions in the word "FNEARLY=".
>> There are two different parameters to specify the absolute and relative
>> tolerances (sensitivities).
>>
>> Offhand it seems that one test or the other would be sufficient; however, one
>> may want to do both tests if the results are being compared against reference
>> values on a system with unknown fp precision.
>>
>> Perhaps David has another justification for doing both tests.
>>
>>
>
> In ftester, David comments on the justification for doing both absolute and
> relative nearness tests in the word "FNEARLY=". If the two numbers being
> compared are very small, their difference may be affected by truncation so that
> a valid nearness test is not possible.
It's been awhile since I've looked at that code, but (I think) I
can still understand it! :-) Here it is:
: fnearly= (f: x y -- s: flag )
(
Leave true if the two floats are nearly equal. This is a
refinement of Dirk Zoller's FEQ to also allow x = y, including
both zero, or to allow approximate equality when x and y are too
small to satisfy the relative approximation mode in the F~
specification.
)
f2dup fexactly= IF f2drop true EXIT THEN
f2dup frel= IF f2drop true EXIT THEN
fabs= ;
As Krishna points out later, FEXACTLY= is the raw mode of F~,
which is an exact comparison of floating point representations.
F= would be more appropriate here, but it's not in ANS94. It's
in pfe and kforth-ppc (I'm not sure about kforth-linux, but that
seems implied by Krishna's remark below), and does the IEEE 754
(also C99) logical comparison, which ignores the sign of zero.
And indeed the point about small x and y is that the relative
comparison becomes meaningless when they are the same order of
magnitude as the tolerance, eps. For example,
1.2 * eps - 1.0 * eps .2
---------------------- = ---- ,
1.2 * eps + 1.0 * eps 2.2
which is not so small. Whereas the FABS= test, with an
independently chosen eps, might be good enough in this
situation. The ordering of the last two tests may not be
optimal for some circumstances. But it seemed to me not
unlikely one would want to say two numbers are nearly equal when
they themselves are close enough to some tolerance, even if they
fail the relative tolerance comparison.
> [Instructive example omitted...]
> A side rant on "F~"
> -------------------
>
> The word F~ really is three different words, which are explicitly spelled out in
> ftester:
>
> FEXACTLY= ( not the same as F= which gives true when comparing 0e and -0e)
> FABS=
> FREL=
>
> It may be justified to combine the first two functions into one word, but
> combining the latter function into F~ is poor design. The relative
> nearness test should have been specified as a separate word in the Forth
> language standard. Using the sign of the tolerance to distinguish between
> absolute and relative nearness tests is confusing and prone to misuse. For
> comparing physical quantities, the tolerance parameter does not even have the
> same units for absolute and relative comparisons (in the latter case, the
> tolerance is dimensionless).
I pretty much agree with this, and I think F= should be standard.
-- David
.
- Follow-Ups:
- Re: New version of John Hayes' tester
- From: Anton Ertl
- Re: New version of John Hayes' tester
- From: Krishna Myneni
- Re: New version of John Hayes' tester
- References:
- New version of John Hayes' tester
- From: Anton Ertl
- Re: New version of John Hayes' tester
- From: Krishna Myneni
- Re: New version of John Hayes' tester
- From: Anton Ertl
- Re: New version of John Hayes' tester
- From: Krishna Myneni
- Re: New version of John Hayes' tester
- From: Anton Ertl
- Re: New version of John Hayes' tester
- From: Krishna Myneni
- Re: New version of John Hayes' tester
- From: Krishna Myneni
- New version of John Hayes' tester
- Prev by Date: Re: RfD: Number Prefixes
- Next by Date: Re: gforth webserver, why isn't forth used all over ecommerce?
- Previous by thread: Re: New version of John Hayes' tester
- Next by thread: Re: New version of John Hayes' tester
- Index(es):
Relevant Pages
|