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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a5e:de0d:: with SMTP id e13mr5771183iok.10.1553892707253; Fri, 29 Mar 2019 13:51:47 -0700 (PDT) X-Received: by 2002:aca:5184:: with SMTP id f126mr4928140oib.44.1553892706870; Fri, 29 Mar 2019 13:51:46 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!136no150544itk.0!news-out.google.com!l81ni128itl.0!nntp.google.com!136no150541itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 29 Mar 2019 13:51:46 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.154.205.191; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40 NNTP-Posting-Host: 87.154.205.191 References: <36c2ff61-8cca-4435-995f-dfc34fa44b69@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <511923fb-dbb9-4e33-82a8-b4bbbf002a6d@googlegroups.com> Subject: Re: type definition for an integer with discrete range From: mario.blunk.gplus@gmail.com Injection-Date: Fri, 29 Mar 2019 20:51:47 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:56005 Date: 2019-03-29T13:51:46-07:00 List-Id: On Friday, March 29, 2019 at 9:24:38 PM UTC+1, Simon Wright wrote: > tra.....g@gmail.com writes: > > > On Friday, March 29, 2019 at 11:10:42 PM UTC+7, mario.b...@gmail.com wrote: > >> Hello, > >> I'm looking for a way to define a type that runs from let say -100 > >> to +100 with gaps of 5 width. Important is to make sure that a value > >> like 7 can not be assigned to the type. > >> > >> something like: > >> > >> type number is new integer range -100 .. 100; > >> -- or > >> subtype number is integer range -100 .. 100; > >> > >> -- with this special thing or something like that: > >> for number'small use 5; -- can not applied here. works with fixed > >> point types only > >> > >> Thanks ! > > > > That's a fixed point type. > > In Ada, that's an integer type. You can tell a real type because its > literals *must* have a decimal point in them. Fixed- and floating-point > types are both real types. > > Mario's code might look like > > Number_Small : constant := 5.0; > type Number is delta Number_Small range -100.0 .. 100.0; > for Number'Small use Number_Small; The problem is that you can assign a variable of type Number 101.0 without getting a compile error. I wrote a test program at https://github.com/Blunk-electronic/ada_training/blob/master/src/type_angle/type_angle.adb where the issue can be tested by yourself. Thanks !