Re: [BLACKBOX] CONSTant expressions

From: [at]} <Robert>
Date: Fri, 18 Jan 2008 18:05:10 +0000

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

Rex Couture wrote:

>> In a language that supports INF why is division by 0
>> SOMETIMES forbidden?

> Interesting. Mathematically, INF is not a number, and therefore not a reasonable value.

I can't resist making a few points ...

Firstly it is an odd coincidence that on the day that I chose to complain that
divison by zero is a 'Good' (for 'good' read 'useful' or 'convenient' as you
wish) thing that should be allowed another thread had links to Ada, and then to
SPARK, which claims that SPARK is a good thing because it prevents division by zero!

Mathematics contains many infinities (the point at infinity is a key ingredient
of projective geometry, and used by many games programmers), but I know what
Rex means. But we are not talking about Maths, we are talking about computer
arithmetic, explicitly about (a subset of) the ANSI/IEEE Std 754-198 floating
point format.

In this format both Infinity & Not-a-Number are supported.

The designers of Component Pascal chose to support INF, and thus implicitly
division by zero. I personally find this convenient far more often than
inconvenient, but clearly the designers of SPARK would disagree.

The designers of Component Pascal chose NOT to support NaN, and thus not
division of zero by zero (0. / 0.). I personally find this convenient far more
often than inconvenient, although VERY occasionally I do want NaNs.

Rex also said that INFs are hard to use in subsequent calculations. Yes, but not
much harder than other numbers. Numerical analysis always requires care.

How many people would correctly anticipate the output of the following module?


My real point is not to question the decision to allow division by zero in
Component Pascal, but to suggest that once the decision has been made it should
be implemented consistently.

In my example module I think the first three results are correct. The forth
result is evidence that the Component Pascal compiler's handling of constants
not only gets division by zero wrong, it gets multiplication by zero wrong also.

Cheers

Robert


MODULE DemoRealSums;

IMPORT Math, Out;

PROCEDURE OutBool (IN str : ARRAY OF CHAR; flg : BOOLEAN);
   BEGIN
     Out.String (str);
     IF flg THEN Out.String (' TRUE') ELSE Out.String (' FALSE') END;
     Out.Ln
   END OutBool;

PROCEDURE Do*;
   CONST
     aCon = 5.;
     bCon = -5.;
     zeroCon1 = aCon * 0.;
     zeroCon2 = bCon * 0.;
   VAR
     a, b, zero1, zero2, inf1, inf2, pi : REAL;
   BEGIN
     a := 5.;
     b := -5.;

     zero1 := a * 0.;
     zero2 := b * 0.;
     OutBool ('zero1 = xero2 ? ', zero1 = zero2); (* TRUE *)

     inf1 := 1. / zero1;
     inf2 := 1. / zero2;
     OutBool ('inf1 = inf2 ? ', inf1 = inf2); (* FALSE *)

     pi := Math.Pi ();
     OutBool ('pi = Pi ? ', pi = Math.Pi ()); (* FALSE *)

     zero1 := zeroCon1;
     zero2 := zeroCon2;
     inf1 := 1. / zero1;
     inf2 := 1. / zero2;
     OutBool ('inf1 = inf2 ? ', inf1 = inf2); (* TRUE *)
   END Do;
END DemoRealSums.


<Q> DevDebug.Unload

<Q> DemoRealSums.Do


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1122802740_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFJleCBDb3V0dXJlIHdyb3RlOlxwYXINClxwYXIN
Cj4+IEluIGEgbGFuZ3VhZ2UgdGhhdCBzdXBwb3J0cyBJTkYgd2h5IGlzIGRpdmlzaW9uIGJ5IDBc
cGFyDQo+PiBTT01FVElNRVMgZm9yYmlkZGVuP1xwYXINClxwYXINCj4gICAgICAgICBJbnRlcmVz
dGluZy4gIE1hdGhlbWF0aWNhbGx5LCBJTkYgaX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gIDEuIC8gemVybzE7XHBhcg0KICAgICBpbmYyICAg
Oj0gIDEuIC8gemVybzI7XHBhcg0KICAgICBPdXRCb29sICgnaW5mMSAgPSBpbmYyICAgICA/ICAn
LCBpbmYxID0gaW5mMik7ICgqICBUUlVFICAqKVxwYXINCiAgIEVORCAgRG87XHBhcg0KRU5EICBE
ZW1vUmVhbFN1bXMuXHBhcg0KXHBhcg0KXHBhcg0KPFE+ICAgRGV2RGVidWcuVW5sb2FkXHBhcg0K
XHBhcg0KPFE+ICAgRGVtb1JlYWxTdW1zLkRvXHBhcg0KXHBhcg0KXHBhcg0KLS0tLVxwYXINClRv
IHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVzc2FnZSB3aXRoIGJvZHkgIlNJR05PRkYgQkxBQ0tCT1gi
IHRvIExJU1RTRVJWQExJU1RTLk9CRVJPTi5DSFxwYXINCn0=
----boundary-LibPST-iamunique-1122802740_-_---
Received on Fri Jan 18 2008 - 19:05:10 UTC

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