comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Standard missing a 'Negative' subtype?...
Date: Sat, 14 Sep 2013 12:57:21 -0700 (PDT)
Date: 2013-09-14T12:57:21-07:00	[thread overview]
Message-ID: <4ae4fa9a-ae46-4a73-ac6d-a578b75f8860@googlegroups.com> (raw)
In-Reply-To: <7b66c649-3796-41ea-b734-a2b14d2dbac3@googlegroups.com>

On Saturday, September 14, 2013 2:49:08 AM UTC-6, Martin wrote:
> Why is there no "Negative" predefined subtype in package Standard?...

Because you don't often need strictly negative numbers... but if you do you could use the following Ada 2012 construct:

    subtype Negative is Integer
    with Static_Predicate => Negative not in Natural;

Or the more traditional Ada83 Range:

    subtype Negative is Integer is range
         Integer'First..Integer'Pred(Natural'First); -- or Integer'First..-1.

(I like using use Integer/Natural/Positive attributes when defining things in terms of subtypes because it avoids hardcoded-constants and makes the type/sybtype relations obvious: the definition becomes stated in terms of it's "type-class".)


  parent reply	other threads:[~2013-09-14 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-14  8:49 Standard missing a 'Negative' subtype? Martin
2013-09-14  9:14 ` Dmitry A. Kazakov
2013-09-14 19:13 ` mockturtle
2013-10-01  2:45   ` J Kimball
2013-09-14 19:57 ` Shark8 [this message]
2013-09-15  3:28 ` Jeffrey R. Carter
2013-09-15  7:36   ` Simon Wright
2013-09-15 16:07     ` Jeffrey R. Carter
2013-09-15 16:49     ` Martin
2013-09-15 17:51       ` J-P. Rosen
2013-09-16 17:44       ` Adam Beneschan
replies disabled

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