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!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: type definition for an integer with discrete range Date: Fri, 29 Mar 2019 20:24:37 +0000 Organization: A noiseless patient Spider Message-ID: References: <36c2ff61-8cca-4435-995f-dfc34fa44b69@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="d3edd0845bf91e08b6bbdb3ecf0226de"; logging-data="12432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hRkMXXk7X9ZU2JqJCZ7LguUFJk1oALtY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (darwin) Cancel-Lock: sha1:JbcCuJMFm5YUFuTT2ytpf1wq218= sha1:6SLaZMZr5AzbXB0EnniWH7IuJ70= Xref: reader01.eternal-september.org comp.lang.ada:56004 Date: 2019-03-29T20:24:37+00:00 List-Id: tranngocduong@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;