Re: [BLACKBOX] CONSTant expressions

From: [at]} <Josef>
Date: Sat, 19 Jan 2008 20:04:51 +0100

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

Case 3:
Surprises me: why is pi different from Math.Pi()?

Case 4:
The IEEE Std has +Inf, -Inf, +0, -0, and NaN besides normal numbers.
It seems that -0 is not supported in constant evaluation, which is done in
the compiler, not at runtime.
My explanation: Mathematics has no concept of -0, only the IEEE Std has it.
Ignoring -0 in constant evaluation keeps the compiler simple. It is probably
not an oversight.
Also the IEEE Std is not mentioned in the BB docu, so it does not claim to be
compliant.
With the widespread adoption of the IEEE Std in Java and C#
it might however be a good idea to stick to that standard, indeed.
Supporting -0 in constant evaluation would probably be fairly simple.

- JT


----- Original Message -----
From: "Robert" <robert.campbell_{([at]})nowhere.xy
To: <BLACKBOX{([at]})nowhere.xy
Sent: Friday, January 18, 2008 7:05 PM
Subject: Re: [BLACKBOX] CONSTant expressions


> 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


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-15748180_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZ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j0gIDEuIC8gemVybzE7XHBhcg0KPiAgICAgaW5mMiAgIDo9ICAxLiAvIHplcm8yO1xwYXIN
Cj4gICAgIE91dEJvb2wgKCdpbmYxICA9IGluZjIgICAgID8gICcsIGluZjEgPSBpbmYyKTsgKCog
IFRSVUUgICopXHBhcg0KPiAgIEVORCAgRG87XHBhcg0KPiBFTkQgIERlbW9SZWFsU3Vtcy5ccGFy
DQo+IFxwYXINCj4gXHBhcg0KPiA8UT4gICBEZXZEZWJ1Zy5VbmxvYWRccGFyDQo+IFxwYXINCj4g
PFE+ICAgRGVtb1JlYWxTdW1zLkRvXHBhcg0KPiBccGFyDQo+IFxwYXINCj4gLS0tLVxwYXINCj4g
VG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9GRiBCTEFDS0JP
WCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIXHBhcg0KXHBhcg0KXHBhcg0KLS0tLVxwYXIN
ClRvIHVuc3Vic2NyaWJlLCBzZW5kIGEgbWVzc2FnZSB3aXRoIGJvZHkgIlNJR05PRkYgQkxBQ0tC
T1giIHRvIExJU1RTRVJWQExJU1RTLk9CRVJPTi59fQBTQWdYSHM=
----boundary-LibPST-iamunique-15748180_-_---
Received on Sat Jan 19 2008 - 20:04:51 UTC

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