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-Thread: 103376,34a625e98d6a8792 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!proxad.net!feeder2-1.proxad.net!news8-e.free.fr!not-for-mail X-Attribution: Jaco Newsgroups: comp.lang.ada Subject: Re: The right way to handle this difference in Ada References: From: Eric Jacoboni Organization: Rogntutdju & Associates Date: Thu, 22 Jul 2004 13:53:42 +0200 Message-ID: User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (darwin) Cancel-Lock: sha1:7Rkgw3Y7kdQLljOp8tLrrbaiPwQ= MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit NNTP-Posting-Date: 22 Jul 2004 13:53:44 MEST NNTP-Posting-Host: 81.56.238.119 X-Trace: 1090497224 news8-e.free.fr 10456 81.56.238.119:41203 X-Complaints-To: abuse@proxad.net Xref: g2news1.google.com comp.lang.ada:2342 Date: 2004-07-22T13:53:44+02:00 List-Id: "vic" writes: > type unsigned_int_12_type is range 0..(2*12)-1; I guess you wanted to say: type unsigned_int_12_type is range 0..(2**12)-1; for unsigned_int_12_type'Size use 12; > and these 2 variables of the above type: > > a: unsigned_int_12_type; > b: unsigned_int_12_type; > > If the code must perform a difference between a and b, say: > > c := a-b > > 1) which should be the type of c? I think it should be something like: C can be a unsigned_int_12_type, as (a - b) _is_ a unsigned_int_12_type (at least, i guess). Of course, if b > a, execution will raise a Constraint_Error... But, as far i've understood, you want to allow situations where b > a ? type Unsigned_Int_12_Type is mod 2**12; for Unsigned_Int_12_Type'size use 12; type Int_12_Type is -(2**11)..+(2**11) - 1; for Int_12_Type'size use 12; C : Int_12_Type; A, B : Unsigned_Int_12_Type; A := 10; B := 12; C := Int_12_Type(A - B); -- C = -2 > type signed_int_12_type is range -unsigned_int_12'last .. > unsigned_int_12'last. > Is this right? No, if unsigned is 0..2^n - 1, signed should be -2^(n-1)..+2^(n-1) - 1 > 2) And I should rename a "-" operation which gets two signed_int_12_type as > operands and returns signed_int_12_type as result? like this : function "-"(A, B : in Unsigned_Int_12_Type) return Int_12_Type; -- �ric Jacoboni, n� il y a 1393940281 secondes