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.2 required=5.0 tests=BAYES_00,FROM_DOMAIN_NOVOWEL, INVALID_DATE,MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!cbosgd!ukma!psuvm.bitnet!psuvax1!burdvax!sdcrdcf!lwall From: lwall@sdcrdcf.UUCP (Larry Wall) Newsgroups: net.lang.ada Subject: Re: Integer Range Question Message-ID: <2872@sdcrdcf.UUCP> Date: Wed, 9-Jul-86 17:05:20 EDT Article-I.D.: sdcrdcf.2872 Posted: Wed Jul 9 17:05:20 1986 Date-Received: Fri, 11-Jul-86 07:15:27 EDT References: <12220812234.39.MENDAL@su-sierra.arpa> Reply-To: lwall@sdcrdcf.UUCP (Larry Wall) Organization: System Development Corporation R&D, Santa Monica List-Id: In article <12220812234.39.MENDAL@su-sierra.arpa> Mendal@SU-SIERRA.ARPA (Geoff Mendal) writes: > We're trying to determine whether the following predefined > integer type is valid (assume that it is the only predefined > integer type): > > type Integer is range 1 .. 0; Maybe not, but perhaps this is: type Integer is range 0 .. -1; You see, a legal range for a pre-defined integer type is one of the two following: -n .. n -n .. n-1 But 1 .. 0 doesn't fit either of these. 0 .. -1 does, though. :-) > The real question here is whether a null range is "symmetric about > zero", as required for all predefined integer types. Also at > issue is whether System.Min_Int *must* be negative, and likewise > System.Max_Int positive. Min_Int and Max_Int are of type universal_integer, which of course contains both positive and negative numbers. However, any implicit conversion of Min_Int or Max_Int to type Integer will raise Constraint_Error! Assuming an implementation with Integer range 0..-1, you couldn't say, for instance: X: Integer; ... if (X = System.Min_Int) - illegal Interestingly enough, I think you CAN say: if (System.Max_Int >= System.Min_Int) - legal, no conversion since there is no implicit conversion. Likewise: if (X in System.Min_Int .. System.Max_Int) -- illegal? if (0 in System.Min_Int .. System.Max_Int) -- legal, and false!?!? But, if (X in Integer) -- legal! (I think) if (0 in Integer) -- illegal??? I dunno. -- Is the 0 converted? Tell me if I'm all wet. In particular, see 4.6(15) and 4.5.2(12). So, the moral of the story is, if you want your program to be portable to an implementation where Min_Int > Max_Int, be sure to guard any "dangerous" code with: if (0 in System.Min_Int .. System.Max_Int) then X := 0; -- non-portable code else Ask_Dumb_Question("Can I ask a dumb question? "); end if; Larry "tour de farce" Wall sdcrdcf!lwall