home *** CD-ROM | disk | FTP | other *** search
-
- -- The purpose of this package is to define an Ada type that has exactly
- -- the operations that are valid for any physical quantity. This package
- -- is then used by the packages that define many physical units. These
- -- packages are used in turn by packages that define operators on physical
- -- units that produce other physical units. Additional packages in this
- -- set provide for outputting of physical units, conversions between
- -- physical units, and other functions needed when working with physical
- -- units.
- --
-
- package PHYSICAL_REAL is
-
- type REAL is private ;
-
- -- Operators available for all types derived from REAL
- --
- -- implicit : := = /=
- --
- --
- -- Physical quantities with the same units can be added
- -- preserving their physical units.
-
- function "+" ( LEFT , RIGHT : REAL ) return REAL ;
-
- -- Physical quantities with the same units can be subtracted
- -- preserving their physical units.
-
- function "-" ( LEFT , RIGHT : REAL ) return REAL ;
-
- -- Multiplying a physical quantity by itself does not produce
- -- the same physical quantity and thus must not be allowed.
- -- Multiplying a physical quantity by a non dimensional quantity
- -- does preserve the units of the physical quantity.
-
- function "*" ( LEFT : FLOAT ;
- RIGHT : REAL ) return REAL ;
-
- function "*" ( LEFT : REAL ;
- RIGHT : FLOAT ) return REAL ;
-
- -- Dividing a physical quantity by a non dimensional quantity
- -- preserves the units of the physical quantity.
-
- function "/" ( LEFT : REAL ;
- RIGHT : FLOAT ) return REAL ;
-
- -- Dividing a physical quantity by itself produces
- -- a non dimensional value.
-
- function "/" ( LEFT , RIGHT : REAL ) return FLOAT ;
-
- -- The absolute value of a physical quantity retains the
- -- same physical units.
-
- function "abs" ( LEFT : REAL ) return REAL ;
-
- -- Equality and inequality are implicitly defined. The other
- -- relational operators must be explicitly defined.
-
- function "<" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
-
- function ">" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
-
- function "<=" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
-
- function ">=" ( LEFT , RIGHT : REAL ) return BOOLEAN ;
-
- -- The primary purpose of this function for the user is
- -- to make constants into values of a specific physical
- -- unit.
- -- The use of this function in the set of physics packages
- -- is to apply the required Ada type to the result of a
- -- non dimensional computation.
-
- function DIMENSION ( LEFT : FLOAT ) return REAL ;
-
- -- The use of this function in the set of physics packages
- -- is to take any physical quantity and get a non dimensional
- -- value in the base floating point arithmetic type in order
- -- to preform computation. This should not be needed by users
- -- of the set of physics packages.
-
- function UNDIMENSION ( LEFT : REAL ) return FLOAT ;
-
- -- For compilers that can make use of INLINE
-
- pragma INLINE ( "+" , "-" , "*" , "/" , "abs" , "<" , ">" , "<=" , ">=" ,
- DIMENSION , UNDIMENSION ) ;
-
- --
- private
- type REAL is new FLOAT ;
- end PHYSICAL_REAL ;
-
- package body PHYSICAL_REAL is
-
- function "+" ( LEFT , RIGHT : REAL ) return REAL is
-
- begin
- return REAL ( FLOAT( LEFT ) + FLOAT ( RIGHT )) ;
- end "+" ;
-
- function "-" ( LEFT , RIGHT : REAL ) return REAL is
-
- begin
- return REAL ( FLOAT( LEFT ) - FLOAT ( RIGHT )) ;
- end "-" ;
-
- function "*" ( LEFT : FLOAT ;
- RIGHT : REAL ) return REAL is
-
- begin
- return REAL ( LEFT * FLOAT( RIGHT )) ;
- end "*" ;
-
- function "*" ( LEFT : REAL ;
- RIGHT : FLOAT ) return REAL is
-
- begin
- return REAL ( FLOAT( LEFT ) * RIGHT) ;
- end "*" ;
-
- function "/" ( LEFT : REAL ;
- RIGHT : FLOAT ) return REAL is
-
- begin
- return REAL ( FLOAT( LEFT ) / RIGHT) ;
- end "/" ;
-
- function "/" ( LEFT , RIGHT : REAL ) return FLOAT is
-
- begin
- return FLOAT ( LEFT ) / FLOAT ( RIGHT ) ;
- end "/" ;
-
- function "abs" ( LEFT : REAL ) return REAL is
-
- begin
- return REAL ( abs( FLOAT( LEFT ))) ;
- end "abs" ;
-
- function "<" ( LEFT , RIGHT : REAL ) return BOOLEAN is
-
- begin
- return FLOAT ( LEFT ) < FLOAT ( RIGHT ) ;
- end "<" ;
-
- function ">" ( LEFT , RIGHT : REAL ) return BOOLEAN is
-
- begin
- return FLOAT ( LEFT ) > FLOAT ( RIGHT ) ;
- end ">" ;
-
- function "<=" ( LEFT , RIGHT : REAL ) return BOOLEAN is
-
- begin
- return FLOAT ( LEFT ) <= FLOAT ( RIGHT ) ;
- end "<=" ;
-
- function ">=" ( LEFT , RIGHT : REAL ) return BOOLEAN is
-
- begin
- return FLOAT ( LEFT ) >= FLOAT ( RIGHT ) ;
- end ">=" ;
-
- function DIMENSION ( LEFT : FLOAT ) return REAL is
-
- begin
- return REAL ( LEFT ) ;
- end DIMENSION ;
-
- function UNDIMENSION ( LEFT : REAL ) return FLOAT is
-
- begin
- return FLOAT ( LEFT ) ;
- end UNDIMENSION ;
-
- end PHYSICAL_REAL ;
-
-