From: mario.blunk.gplus@gmail.com
Subject: Re: type definition for an integer with discrete range
Date: Fri, 29 Mar 2019 13:51:46 -0700 (PDT)
Date: 2019-03-29T13:51:46-07:00 [thread overview]
Message-ID: <511923fb-dbb9-4e33-82a8-b4bbbf002a6d@googlegroups.com> (raw)
In-Reply-To: <lypnq92zui.fsf@pushface.org>
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 !
next prev parent reply other threads:[~2019-03-29 20:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-29 16:10 type definition for an integer with discrete range mario.blunk.gplus
2019-03-29 16:34 ` tranngocduong
2019-03-29 16:46 ` mario.blunk.gplus
2019-03-30 4:17 ` tranngocduong
2019-03-30 4:19 ` tranngocduong
2019-03-29 20:24 ` Simon Wright
2019-03-29 20:51 ` mario.blunk.gplus [this message]
2019-03-29 21:24 ` Simon Wright
2019-03-30 20:44 ` mario.blunk.gplus
2019-03-30 22:13 ` Jere
2019-04-01 6:59 ` mario.blunk.gplus
2019-04-01 15:52 ` AdaMagica
2019-04-01 16:27 ` Simon Wright
2019-04-01 16:41 ` AdaMagica
2019-03-29 21:57 ` Dmitry A. Kazakov
2019-03-30 21:45 ` John Perry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox