comp.lang.ada
 help / color / mirror / Atom feed
From: stt@dsd.camb.inmet.com (Tucker Taft)
Subject: Re: Q: common types?!
Date: Thu, 29 Sep 1994 15:35:21 GMT
Date: 1994-09-29T15:35:21+00:00	[thread overview]
Message-ID: <CwwDyy.75w@inmet.camb.inmet.com> (raw)
In-Reply-To: 36c1c0$lve@pong.lasc.lockheed.com

In article <36c1c0$lve@pong.lasc.lockheed.com>,
Tony Leavitt <tony@deepthought.Sgi.COM> wrote:
>I have a question for all you Ada wizards.  I do not have a lot of experience
>with Ada (only about 3000 lines), and I have begun to start making a common
>types package.  This package would define all kinds of types for feet, nautical
>miles, degrees, radians, etc, ad nuasium, for all different kinds and sizes
>of float and integers.  Am I about to go insane by trying this?  Or, does
>this exist already on the Internet somewhere?  If I was to attempt to do this
>how would you recommend about doing it?

You could simplify your life by making some of this a generic
package, to be instantiated with the "base" floating point type
and/or integer type of interest.  Put all of the various
miles, feet, degrees, etc. in such a generic package.

Put the general constants into a separate package.

Finally, if you really feel the need, put the numeric types into 
a third package, with appropriate instantiations of your generic.
However, I recommend against this if you can avoid it.  Having
a centralized "types" package is not a wise way to organize
an Ada program, IMHO.  You should declare types with the operations
that operate on them, in their own package.  Grouping them
all into one giant package is a way to create maintenance,
portability, and general software engineering nightmares.


>Here is a sample of what I started to do:
>
>package Common_Types is
>
>   type float64 is new float ;
>   for  float64'SIZE use 64 ;
>   type float32 is new float ;
>   for  float32'SIZE use 32 ;
>
>   type integer64 is new integer ;
>   for  integer64'SIZE use 64 ;
>   type integer32 is new integer ;
>   for  integer32'SIZE use 32 ;
>   type integer16 is new integer ;
>   for  integer16'SIZE use 16 ;
>   type integer8 is new integer ;
>   for  integer8'SIZE use 8 ;

As someone else pointed out, the above will never work in Ada.
You can't turn a 32-bit integer into an 8-bit integer
by just squeezing the bits a bit.  You have got to
impose a range constraint as well, at which point you
should declare the range when you declare the type, as follows:

    type integer64 is range -2**63 .. 2**63-1;
    type integer32 is range -2**31 .. 2**31-1;
    type integer16 is range -2**15 .. 2**15-1;
    type integer8  is range -2**7 .. 2**7-1;

Similarly for floating point:

    type float64 is digits 15;
    type float32 is digits 6;

Note that in Ada 9X, the language-defined package
Interfaces already has these.

> ...
>Tony Leavitt
>
>Lockheed Aeronautical Systems Company
>Marietta,  GA 30063-0670
>Voice: (404) 494-7648, Fax:(404) 494-6989
>Email: tony@gelac.lasc.lockheed.com

-Tucker Taft



  parent reply	other threads:[~1994-09-29 15:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-28 15:16 Q: common types?! Tony Leavitt
1994-09-29 11:37 ` Peter Hermann
1994-09-29 15:35 ` Tucker Taft [this message]
1994-10-05  4:40 ` Daniel Wengelin
1994-10-12 17:39   ` gamache
1994-10-12 20:36     ` Kraig Hanson
1994-10-12 21:37     ` Robert Dewar
replies disabled

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