From: martin.dowie@btopenworld.com (Martin Dowie)
Subject: Re: New limited range type?
Date: 11 Nov 2003 02:18:47 -0800
Date: 2003-11-11T02:18:47-08:00 [thread overview]
Message-ID: <af783afe.0311110218.5649a486@posting.google.com> (raw)
In-Reply-To: bopr58$1hil7c$1@ID-25716.news.uni-berlin.de
> > How about:
> >
> > function S'Limit (X:...
>
> Or maybe Limit_to_Bounds? Wordy, but clearer.
I still prefer 'Limit ;-)
I don't think the extra words add much, if I saw "'Limit" and I'd never
seen it before I'd simply look up the RM. There are loads of existing
attribute names that could be wordier to be made clearer...
> > While that's good technique, I presume your NOT saying that the RM would
> > require this?
>
> I thinkj it would be necessary to adopt this approach, since the base range
> required cannot be guessed. I think the neatest solution is to require a
> named type with this range to be declared, and then subtypes with the
> required limited ranges to be declared and used to indicate the bounds of
> the operation.
No it isn't - like I said in my original post, it can all be done with
generics as it is - it's just a pain to have to keep including new
instances when it could easily be part of the language - see example
at the end of this reply.
> > Also, why not allow it for any scalar type?
>
> Yes, I think you're right. Shall I send a proposal to ada-comment?
Ok :-)
-----------------------------
-- generic_limit_fixed.ads --
-----------------------------
generic
type T is delta <>;
function Generic_Limit_Fixed (V : T'Base) return T;
-----------------------------
-- generic_limit_fixed.adb --
-----------------------------
function Generic_Limit_Fixed (V : T'Base) return T is
begin
if V < T'First then
return T'First;
elsif V > T'Last then
return T'Last;
else
return V;
end if;
end Generic_Limit_Fixed;
-----------------------------
-- generic_limit_float.ads --
-----------------------------
generic
type T is digits <>;
function Generic_Limit_Float (V : T'Base) return T;
-----------------------------
-- generic_limit_float.adb --
-----------------------------
function Generic_Limit_Float (V : T'Base) return T is
begin
if V < T'First then
return T'First;
elsif V > T'Last then
return T'Last;
else
return V;
end if;
end Generic_Limit_Float;
---------------
-- tests.ads --
---------------
with Generic_Limit_Fixed;
with Generic_Limit_Float;
package Tests is
type Safe_Fixed_Degrees is
delta 0.125 range -180.00 .. 180.0;
function Limit is
new Generic_Limit_Fixed (Safe_Fixed_Degrees);
type Safe_Float_Degrees is
digits 6 range -180.00 .. 180.0;
function Limit is
new Generic_Limit_Float (Safe_Float_Degrees);
end Tests;
--------------
-- test.adb --
--------------
with Ada.Text_IO; use Ada.Text_IO;
with Tests; use Tests;
procedure Test is
procedure Test_Float is
A, B, C : Safe_Float_Degrees;
begin
B := 170.0;
C := 50.0;
A := Limit (B + C);
Put_Line ("A =" & Safe_Float_Degrees'Image (A));
end Test_Float;
procedure Test_Fixed is
A, B, C : Safe_Fixed_Degrees;
begin
B := 170.0;
C := 50.0;
A := Limit (B + C);
Put_Line ("A =" & Safe_Fixed_Degrees'Image (A));
end Test_Fixed;
begin
Test_Float;
Test_Fixed;
end Test;
next prev parent reply other threads:[~2003-11-11 10:18 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-07 15:51 New limited range type? Martin Dowie
2003-11-07 15:57 ` Hyman Rosen
2003-11-07 16:20 ` Martin Dowie
2003-11-07 16:36 ` Stephane Richard
2003-11-07 16:59 ` Hyman Rosen
2003-11-07 18:18 ` Martin Dowie
2003-11-07 20:11 ` Larry Hazel
2003-11-07 22:40 ` Martin Dowie
2003-11-07 23:31 ` Larry Hazel
2003-11-12 8:22 ` Jean-Pierre Rosen
2003-11-12 15:00 ` Hyman Rosen
2003-11-12 15:34 ` Robert I. Eachus
2003-11-12 17:37 ` tmoran
2003-11-07 18:19 ` Mike Silva
2003-11-07 19:03 ` Marin David Condic
2003-11-07 18:05 ` Mike Silva
2003-11-08 21:58 ` Nick Roberts
2003-11-09 14:34 ` Martin Dowie
2003-11-11 5:13 ` Nick Roberts
2003-11-11 10:18 ` Martin Dowie [this message]
2003-11-11 10:35 ` Martin Dowie
2003-11-11 10:41 ` Lutz Donnerhacke
2003-11-11 12:37 ` Marin David Condic
2003-11-11 14:19 ` Martin Dowie
2003-11-11 12:34 ` Marin David Condic
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox