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-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: The right way to handle this difference in Ada Date: Thu, 22 Jul 2004 13:07:33 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de VLkZAWrGU6/ui1mzl+hdkQ7lw+ntGT59UTyjBfSo3a9J3TSsE= User-Agent: Opera M2/7.51 (Win32, build 3798) Xref: g2news1.google.com comp.lang.ada:2343 Date: 2004-07-22T13:07:33+01:00 List-Id: On Thu, 22 Jul 2004 12:23:09 +0200, vic wrote: > Please consider this type: > > type unsigned_int_12_type is range 0..(2*12)-1; > > 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: > > type signed_int_12_type is range -unsigned_int_12'last .. > unsigned_int_12'last. > > Is this right? I'm guessing that what you really require is to be able to pack one or more 12-bit integers into a record. Is this correct? If it is, the solution to your problem is likely to be this: subtype My_Integer is Integer range 0..2**12-1; A, B: My_Integer; C: Integer range -My_Integer'Last..My_Integer'Last; ... C := A-B; ... type My_Record is record ... X, Y: My_Integer; ... end record; for My_Record use record ... X at 5 range 0..11; Y at 5 range 12..23; ... end record; The idea is that you use a standard base type for the arithmetic, declaring subtypes which restrict the range as appropriate, and then tell the compiler explicitly how to squeeze values into 12-bit parts of the record type. With luck, the compiler will oblige (or tell you why it cannot). Des this help? > 2) And I should rename a "-" operation which gets two signed_int_12_type > as operands and returns > signed_int_12_type as result? Hopefully the above technique will work for you, and enable to avoid the need to declare your own arithmetic operations. -- Nick Roberts