comp.lang.ada
 help / color / mirror / Atom feed
From: Eric Jacoboni <jaco@neottia.net>
Subject: Re: The right way to handle this difference in Ada
Date: Thu, 22 Jul 2004 13:53:42 +0200
Date: 2004-07-22T13:53:44+02:00	[thread overview]
Message-ID: <m2658g5kc9.fsf@mac.scrogneugneu.org> (raw)
In-Reply-To: cdo4ic$q8f$1@e3k.asi.ansaldo.it

"vic" <ppp@ppp.it> 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



  reply	other threads:[~2004-07-22 11:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-22 10:23 The right way to handle this difference in Ada vic
2004-07-22 11:53 ` Eric Jacoboni [this message]
2004-07-22 12:07 ` Nick Roberts
2004-07-22 13:03 ` Dmitry A. Kazakov
2004-07-22 13:22   ` Eric Jacoboni
2004-07-22 13:34     ` Dmitry A. Kazakov
2004-07-22 13:34 ` Björn Persson
2004-07-22 17:52 ` Georg Bauhaus
2004-07-22 18:10   ` Georg Bauhaus
2004-07-23  3:41 ` Steve
2004-07-23 12:47   ` Marius Amado Alves
2004-07-24  3:14     ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox