comp.lang.ada
 help / color / mirror / Atom feed
From: tony@deepthought.Sgi.COM (Tony Leavitt)
Subject: Q: common types?!
Date: 28 Sep 1994 15:16:16 GMT
Date: 1994-09-28T15:16:16+00:00	[thread overview]
Message-ID: <36c1c0$lve@pong.lasc.lockheed.com> (raw)

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?

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 ;

   ----------------------------------------------------------------------------
   --  Linear Distance Types
   ----------------------------------------------------------------------------

   FEET_PER_NAUTICAL_MILE : constant float := 6076.115 ;
   FEET_PER_STATUTE_MILE  : constant float := 5280.0 ;
   FEET_PER_KILOMETER	  : constant float := 3280.8399 ;
   FEET_PER_METER	  : constant float := 3.2808399 ;

   type Nautical_Miles_f64 is new float64 ;
   subtype NM_f64 is Nautical_Miles_f64 ;
   type Nautical_Miles_f32 is new float32 ;
   subtype NM_f32 is Nautical_Miles_f32 ;
   type Nautical_Miles_i64 is new integer64 ;
   subtype NM_i64 is Nautical_Miles_i64 ;
   type Nautical_Miles_i32 is new integer32 ;
   subtype NM_i32 is Nautical_Miles_i32 ;
   type Nautical_Miles_i16 is new integer16 ;
   subtype NM_i16 is Nautical_Miles_i16 ;
   type Nautical_Miles_i8 is new integer8 ;
   subtype NM_i8 is Nautical_Miles_i8 ;

   type Statute_Miles_f64 is new float64 ;
   subtype MI_f64 is Statute_Miles_f64 ;
   type Statute_Miles_f32 is new float32 ;
   subtype MI_f32 is Statute_Miles_f32 ;
   type Statute_Miles_i64 is new integer64 ;
   subtype MI_i64 is Statute_Miles_i64 ;
   type Statute_Miles_i32 is new integer32 ;
   subtype MI_i32 is Statute_Miles_i32 ;
   type Statute_Miles_i16 is new integer16 ;
   subtype MI_i16 is Statute_Miles_i16 ;
   type Statute_Miles_i8 is new integer8 ;
   subtype MI_i8 is Statute_Miles_i8 ;

   type Feet_f64 is new float64 ;
   subtype FT_f64 is Feet_f64 ;
   type Feet_f32 is new float32 ;
   subtype FT_f32 is Feet_f32 ;
   type Feet_i64 is new integer64 ;
   subtype FT_i64 is Feet_i64 ;
   type Feet_i32 is new integer32 ;
   subtype FT_i32 is Feet_i32 ;
   type Feet_i16 is new integer16 ;
   subtype FT_i16 is Feet_i16 ;
   type Feet_i8 is new 

   ----------------------------------------------------------------------------
   --  Angular Distance Types
   ----------------------------------------------------------------------------

   type Degrees_f64 is new float64 ;
   type Degrees_f32 is new float32 ;

   -- same for radians.

   ----------------------------------------------------------------------------
   --  Earth Position Types
   ----------------------------------------------------------------------------

   subtype Latitude_f64 is Degrees_f64 range -90.0 .. +90.0 ;
   subtype Latitude_f32 is Degrees_f32 range -90.0 .. +90.0 ;

   -- Same for Longitude, heading, bearing, etc

   ----------------------------------------------------------------------------
   --  Functions
   ----------------------------------------------------------------------------

   function sin ( x : Degrees_f64 )	return float64 ;
   function sin ( x : Degrees_f32 )	return float32 ;
   function sin ( x : Radians_f64 )	return float64 ;
   function sin ( x : Radians_f32 )	return float32 ;

   function convert (x : degrees_f64) return degrees_32 ;
   function convert (x : radians_f64) return degrees_i16 ;

   -- etc, etc, etc, etc, until you puke.  Same for operators "*", and "+" which
   -- would do all kinds of type conversion and make sure the units are protected.

end Common_Types ;

-- 

Tony Leavitt

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



             reply	other threads:[~1994-09-28 15:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-28 15:16 Tony Leavitt [this message]
1994-09-29 11:37 ` Q: common types?! Peter Hermann
1994-09-29 15:35 ` Tucker Taft
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