From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7f5c70275787af8 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Ada vs Delphi? Date: 1999/08/17 Message-ID: <37B9F65B.59303417@mitre.org>#1/1 X-Deja-AN: 513995862 Content-Transfer-Encoding: 7bit References: <37ab421a.5414989@news.total.net> <37ab8bd1.0@news.pacifier.com> <37ae1fc8.653954@news.clara.net> <37AE980F.15E6A15C@maths.unine.ch> <37b12a3f.43564067@news.total.net> <37B27FE8.6E09569E@Maths.UniNe.CH> <37b54516.54588055@news.total.net> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 934933880 16710 129.83.41.77 (17 Aug 1999 23:51:20 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 17 Aug 1999 23:51:20 GMT Newsgroups: comp.lang.ada Date: 1999-08-17T23:51:20+00:00 List-Id: Andre Ratel wrote: > > My post is a bit long. I apologize, but I really want to get to the > bottom of this. Fine but you need to understand that the water is really deep. > A safe language should be such that all evaluations are performed > using the largest set of numerals available (longint for integers, > extended for real numbers). The responsability of the programmer > would be then to choose the appropriate type of variables for > _storing_ the results in memory. (I am aware that this might lead > to problems in efficiency.) Hmmm. Ada has a several types one of which is _universal_integer_ which really are universal types, containing, in this case, all possible integers. It is possible to generate values of these universal types at run-time, and there are specific rules for how to value such expressions. (For static expressions, you get them right, at compile time, no matter how far out they are.) But what about expressions containing mixtures of two different classes? Things get really tricky. For example, how do you evaluate: System.Max_Binary_Modulus + System.Min_Int? At compile time of course, but what if one value is a run-time value? (Assume that Long_Integer is the largest integer type, and Long_Modular is the largest modular type and they have the same number of bits): X: Modular := ...; Y: Modular := Modular'Modulus - X; Foo'Modulus cannot be represented as a value of type Foo for any Foo, but in this case there is no larger type. So how do you deal with this case? As a special case, since the idiom is useful. But what about: X: Integer := ...; Y: Modular := Modular(Modular'Modulus + X); It looks like you should use the Modular type to evaluate this expression, but you can't, you really have to follow the rules and do the addition, then the conversion. The conversion will fail unless X is negative, but if you convert X first, the conversion would fail only when it shouldn't. Again, you might want to special case such an expression, because no arithmetic operations are required. In fact the compiler might not even need to treat it as a special case. (Modular'Modulus is congruent to 0 mod itself, so you just have to do the constraint check right. There is an even more vexatious problem with no static values. Watch: X: Integer := ...; Y: Modular := ...; if Integer'Pos(X) - Modular'Pos(Y) > 42 then... Now what do you do? (For those who are not Ada experts those operands and operations are of type _universal_integer_, the result is of course Boolean.) The expression must be evaluated at run-time, and there is no machine arithmetic type which will always get the right answer. For those of you who are Ada experts, yes there is an AI on the subject, but we are still working on it... In Ada I had to work hard to get a legal example of the problem, but what does Delphi do in a similar case? > * For all binary operators (an operator that takes two > operands), both operands are converted to their common > type before the operation. The _common_type_ is the > predefined integer type with the the smallest range that > includes all possible values of both types. For instance, > the common type of integer and byte is integer, and the > common type of integer and word is longint. The operation > is performed using the precision of the common type, and > the result type is the common type. But there is no possible common type between (long) integer and (long) unsigned! -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...