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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Generic formals and Aspects Date: Tue, 19 Jul 2016 18:04:15 +0200 Organization: A noiseless patient Spider Message-ID: References: <59656e9a-8826-490e-9c35-f13f8ff1aa91@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 19 Jul 2016 16:04:18 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="45bffd6a911624777cad79aac3181090"; logging-data="6250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Kx0LH9XldHwFPZ3mB3S9D" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <59656e9a-8826-490e-9c35-f13f8ff1aa91@googlegroups.com> Cancel-Lock: sha1:L2S7hptvSTFEgXoxxvz9BVXByqk= Xref: news.eternal-september.org comp.lang.ada:31099 Date: 2016-07-19T18:04:15+02:00 List-Id: 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