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 11:54:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Saturated Math Date: Fri, 30 May 2003 13:55:53 -0500 Organization: Posted via Supernews, http://www.supernews.com 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> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:38137 Date: 2003-05-30T13:55:53-05:00 List-Id: 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; 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.