Re: Numeric problem in BlackBox 1.4

From: [at]} <robert.d.campbell{>
Date: Wed, 19 Feb 2003 09:52:18 +0000 (GMT)

----boundary-LibPST-iamunique-325506322_-_-
Content-type: text/plain

This discussion of floating point comparison
is rather relevant.

Yesterday I posted the 'algorithm'

IF (a + b) = b THEN ...

which correctly tests that 'b is negligibly small compared to a'.

I also criticised the unconditional use of

IF ABS (a - b) < eps THEN ...

on the grounds that you do not always know a suitable value for eps.

A few weeks ago I published the Control CtlsRealField (on Helmut's page)
which uses the algorithm

IF a = b THEN ...

to correctly test that 'b hasn't changed since a copy of it was last stored in
a'.

A few days ago I published the Control CtlsUnitField which used the
algorithm

IF a = b THEN ...

to INCORRECTLY test that 'b hasn't changed since a copy of it was
last stored in a other than by being scaled up and down by the same
floating point number'.

I subsequently published a 'correction' which uses the algorithm

IF IsRelEq (a, b, 1.E-15) THEN ...

where the code for IsRelEq should be

PROCEDURE IsRelEq (x, y, relErr : REAL) : BOOLEAN;
  BEGIN
    ASSERT (relErr >= 0., 20);
    IF x = y THEN RETURN TRUE END;
    RETURN (ABS (x - y) / MAX (ABS (x), ABS (y))) <= relErr
  END IsRelEq;

(In fact the currently published version of IsRelEq contains another error;
I shall correct it shortly. And even this code is probably wrong if x = INF
& y = -INF)


>> I am very cautious with *any* expectations regarding floating point
>> expressions.

Unexpected behaviour, such as PROCEDURES returning 80-bit precision
on the stack, can be controlled by setting the floating point unit
flags explicitly. If anyone needs to do this I can give examples
on how to do this in BlackBox (on Pentiums & Athlons).


The bottom line? - numerical analysis is not always totally trivial.
And as for the start of this thread; I can't think of anything
more reasonable than rounding a symbolic constant (such as
1.000000000000000001) to the nearest representable 64-bit IEEE
REAL (eg 1.0 ).


Regards

Robert


--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy

Current posting policy:

a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.

b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.


----boundary-LibPST-iamunique-325506322_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFRoaXMgZGlzY3Vzc2lvbiBvZiBmbG9hdGluZyBw
b2ludCBjb21wYXJpc29uXHBhcg0KaXMgcmF0aGVyIHJlbGV2YW50LlxwYXINClxwYXINClllc3Rl
cmRheSBJIHBvc3RlZCB0aGUgJ2FsZ29yaXRobSdccGFyDQpccGFyDQpJRiAgKGEgKyBiKSA9IGIg
VEhFTiAuLi5ccGFyDQpccGFyDQp3aGljaCBjb3JyZWN0bHkgdGVzdHMgdGhhdCAnYiBpcyBuZWds
aWdpYmx5IHNtYWxsIGNvbXBhcmVkIHRvIGEnLlxwYXINClxwYXINCkkgYWxzbyBjcml0aWNpc2Vk
IHRoZSB1bmNvbmRpdGlvbmFsIHVzZSBvZlxwYXINClxwYXINCklGIEFCUyAoYSAtIGIpIDwgZXBz
IFRIRU4gLi4uXHBhcg0KXHBhcg0Kb24gdGhlIGdyb3VuZHMgdGhhdCB5b3UgZG8gbm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Gxpc3Qgb3duZXIgYXRccGFyDQogICBvd25lci1ibGFj
a2JveEBvYmVyb24uY2hccGFyDQpccGFyDQpDdXJyZW50IHBvc3RpbmcgcG9saWN5OlxwYXINClxw
YXINCmEpIFRvIHBvc3QgeW91IHNob3VsZCB1c2UgdGhlIHNhbWUgYWRkcmVzcyBieSB3aGljaCB5
b3UgYXJlIHN1YnNjcmliZWQgdG8gdGhlIG1haWxpbmcgbGlzdC4gVGhhdCB3YXksIHRoZSBsaXN0
IHNlcnZlciB3aWxsIHJlY29nbml6ZSB5b3UgYXMgc3Vic2NyaWJlciBhbmQgZm9yd2FyZCB5b3Vy
IHBvc3RpbmcgaW1tZWRpYXRlbHksIHdpdGhvdXQgY3JlYXRpbmcgYW55IG92ZXJoZWFkLlxwYXIN
ClxwYXINCmIpIElmLCBmb3Igc29tZSByZWFzb24sIHlvdSBjYW5ub3QgcG9zdCBmcm9tIHRoZSBh
ZGRyZXNzLCBieSB3aGljaCB5b3UgYXJlIHN1YnNjcmliZWQsIHlvdXIgbWVzc2FnZSB3aWxsIGJl
IG1vZGVyYXRlZCB0byBhdm9pZCBzcGFtLiBQbGVhc2UgdW5kZXJzdGFuZCB0aGF0IG1vZGVyYXRp
b24gd2lsbCBvZnRlbiBjYXVzZSBzb21lIGRlbGF5LCBpbiBwYXJ0aWN1bGFyIG92ZXIgd2Vla2Vu
ZHMgb3IgaG9seWRheXMuXHBhcg0KfQ==


----boundary-LibPST-iamunique-325506322_-_---
Received on Wed Feb 19 2003 - 10:52:18 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:29:26 UTC