[BLACKBOX] REAL Exponent (Was Another (?) Compiler Trap)

From: Campbell, Robert (SELEX GALILEO, UK) <"Campbell,>
Date: Mon, 3 Mar 2008 12:23:22 -0000

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

Hi

Regarding my attempt to extract the exponent of a floating point number
in 'Pure' CP
my 'old' (and slow, but no matter) routine was:

CONST
  ln2 = 0.6931471805599453094172321; (* Correct to 25 digits !!!
*)
BEGIN
  exp := SHORT (ENTIER ((Math.Ln (ABS (x))) / ln2));


This (with some other corrections not relevant to this comment) has
worked for
18 months, then failed today with x = 31.999999999999996; One more or
less
9 and it works. Embarassingly it was a customer who found this!
Fortunately
a strategically placed ASSERT prevented serious consequences.

Odds against, 10^-15 ?, or rather 100%. These details ALWAYS bite
eventually.

The problem, of course, is the Ln rounding.

The line:
 exp := SHORT (ENTIER ((Math.Ln (ABS (x))) / Math.Ln (2.)))

works here, because of the 80 bits left on the stack. But I wouldn't
like to try to *prove* it always works.


Cheers

Robert

SELEX Sensors and Airborne Systems Limited
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-166017762_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWV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yZWNpcGllbnQg
cGxlYXNlIGRlbGV0ZSBpdCBmcm9tIHlvdXIgc3lzdGVtIGFuZCBub3RpZnkgdGhlIHNlbmRlci5c
cGFyDQpZb3Ugc2hvdWxkIG5vdCBjb3B5IGl0IG9yIHVzZSBpdCBmb3IgYW55IHB1cnBvc2Ugbm9y
IGRpc2Nsb3NlIG9yXHBhcg0KZGlzdHJpYnV0ZSBpdHMgY29udGVudHMgdG8gYW55IG90aGVyIHBl
cnNvbi5ccGFyDQoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKlxwYXINClxwYXINClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1
YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBM
SVNUU0VSVkBMSVNUUy5PQkVST04uQ0h9fQBudC1U
----boundary-LibPST-iamunique-166017762_-_---
Received on Mon Mar 03 2008 - 13:23:22 UTC

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