comp.lang.ada
 help / color / mirror / Atom feed
From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: Generic formals and Aspects
Date: Tue, 19 Jul 2016 18:04:15 +0200
Date: 2016-07-19T18:04:15+02:00	[thread overview]
Message-ID: <nmlj21$63a$1@dont-email.me> (raw)
In-Reply-To: <59656e9a-8826-490e-9c35-f13f8ff1aa91@googlegroups.com>

Le 19/07/2016 à 17:49, olivermkellogg@gmail.com a écrit :
>    generic
>>       type Source_Type is range <>
>>         with Static_Predicate =>
>>           Long_Long_Integer (Destination_Type'First)
>>             >= Long_Long_Integer (Source_Type'First)
>>           and Long_Long_Integer (Destination_Type'Last)
>>             <= Long_Long_Integer (Source_Type'Last);
>>       type Destination_Type is range <>;
>>    function Saturate (X : Source_Type) return Destination_Type;
>> 
Tip: you don't need to convert to Long_Long_Integer here (non portable,
etc...). Use:
          Destination_Type'Pos (Destination_Type'First)
            >= Source_Type'Pos (Source_Type'First)
          and Destination_Type'Pos (Destination_Type'Last)
            <= Source_Type'Pos (Source_Type'Last);

Since 'Pos returns Universal_Integer, you can compare values of
different types.

FWIW...
-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

  reply	other threads:[~2016-07-19 16:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-17 13:17 Generic formals and Aspects Simon Wright
2014-10-17 16:04 ` Shark8
2014-10-17 18:51   ` Simon Wright
2014-10-18  1:43 ` Shark8
2016-07-19 15:49 ` olivermkellogg
2016-07-19 16:04   ` J-P. Rosen [this message]
2016-07-19 16:05   ` Shark8
2016-07-19 18:00     ` olivermkellogg
2016-07-19 19:23       ` Randy Brukardt
2016-07-20 15:09         ` olivermkellogg
replies disabled

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