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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-30 12:31:12 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!in.100proofnews.com!in.100proofnews.com!news-out.visi.com!petbe.visi.com!uunet!ash.uu.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Saturated Math Date: 30 May 2003 15:31:11 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <3ECFF541.1010705@attbi.com> <3ED0B820.5050603@noplace.com> <3ED2096F.3020800@noplace.com> <3ED353BE.40605@noplace.com> <3ED4A323.3000909@noplace.com> <3ED5E8DE.8070308@noplace.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1054323071 16543 199.172.62.241 (30 May 2003 19:31:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 30 May 2003 19:31:11 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:38144 Date: 2003-05-30T15:31:11-04:00 List-Id: "Randy Brukardt" writes: > Dale Stanbrough wrote in message ... > >I don't like the idea that you have to create a dummy type... > > > > type Pretend_Type is new Integer range 1..5; > > package Saturated_Int is new Saturate (Pretend_Type); > > ... > > > >It seems a bit clunky just to get around the type system. I > >thought of passing in an upper and lower bound to the generic, > >but what type should they be? You could make them integer, but > >what if you wanted saturating integers with a larger range than > >Standard.Integer? > > > It's mildly annoying that Ada doesn't have a standard name for the > largest range integer type supported by the implementation. (The > standard defines Root_Integer, but it is not a name that you can use in > a program.) But it is easy enough to declare: > > type Largest_Integer_Type is range System.Min_Int .. System.Max_Int; > > The, the generic could look something like: > > generic > Lower_Bound, Upper_Bound : Largest_Integer_Type; > package Saturated_Math is > type Saturated_Type is Lower_Bound .. Upper_Bound; But the bounds are not static expressions, as required, and you're missing "range". Or did you mean "subtype"? > function "+" (Left, Right : Saturated_Type) return > Saturated_Type; > ... > end Saturated_Math; > > Using this would be virtually the same as using predefined integer > types. (We use something like this to emulate the target machine's math > in the Janus/Ada compiler. Why do that? We needed it for the Unisys 2200 > compiler, as that is a one's complement, 36-bit machine.) > > Randy.