[BACK]Return to multprec_floating_numbers.ads CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / PHC / Ada / Math_Lib / Numbers

Annotation of OpenXM_contrib/PHC/Ada/Math_Lib/Numbers/multprec_floating_numbers.ads, Revision 1.1.1.1

1.1       maekawa     1: with Multprec_Natural_Numbers;           use Multprec_Natural_Numbers;
                      2: with Multprec_Integer_Numbers;           use Multprec_Integer_Numbers;
                      3: with Standard_Floating_Numbers;          use Standard_Floating_Numbers;
                      4:
                      5: package Multprec_Floating_Numbers is
                      6:
                      7: -- DESCRIPTION :
                      8: --   This package provides operations to deal with floating-point numbers
                      9: --   of arbitrary length.  The size of the fraction remains fixed during
                     10: --   computations, but can be adjusted.  The exponent has no fixed size.
                     11: --   Mixed-precision arithmetic is fully supported: the size of the result
                     12: --   in any binary operation is the maximal size of the operands.
                     13:
                     14:   type Floating_Number is private;
                     15:
                     16: -- CONSTRUCTORS :
                     17:
                     18:   function Create ( i : integer ) return Floating_Number;
                     19:   function Create ( i : Integer_Number ) return Floating_Number;
                     20:   function Create ( f : double_float ) return Floating_Number;
                     21:
                     22:   function Create ( fraction,exponent : integer ) return Floating_Number;
                     23:   function Create ( fraction : Integer_Number;
                     24:                     exponent : integer ) return Floating_Number;
                     25:   function Create ( fraction : integer;
                     26:                     exponent : Integer_Number ) return Floating_Number;
                     27:   function Create ( fraction,exponent : Integer_Number ) return Floating_Number;
                     28:
                     29:   -- DESCRIPTION :
                     30:   --   A floating point number consists of a fraction and exponent.
                     31:
                     32: -- SELECTORS :
                     33:
                     34:   function Fraction ( f : Floating_Number ) return Integer_Number;
                     35:   function Exponent ( f : Floating_Number ) return Integer_Number;
                     36:
                     37:   -- DESCRIPTION :
                     38:   --   Returns the fraction and the exponent.  Warning: sharing!
                     39:   --   We have that f = Fraction(f)*10**Exponent(f).
                     40:
                     41:   function Size_Fraction ( f : Floating_Number ) return natural;
                     42:   function Size_Exponent ( f : Floating_Number ) return natural;
                     43:
                     44:   -- DESCRIPTION :
                     45:   --   Returns the length of the coefficient vector of the representations
                     46:   --   of fraction and exponent as integer numbers.
                     47:   --   Size_Fraction(f) = 1 corresponds to the precision of the standard
                     48:   --   double floating-point numbers.
                     49:
                     50:   function Decimal_Places_Fraction ( f : Floating_Number ) return natural;
                     51:   function Decimal_Places_Exponent ( f : Floating_Number ) return natural;
                     52:
                     53:   -- DESCRIPTION :
                     54:   --   Returns the number of decimal places in fraction and exponent.
                     55:
                     56:   function Decimal_to_Size ( deci : natural ) return natural;
                     57:
                     58:   -- DESCRIPTION :
                     59:   --   Returns the smallest size to obtain the given number of decimal places.
                     60:   --   This is useful for the "Set_Size" operation.
                     61:
                     62:   function AbsVal ( f : Floating_Number ) return Floating_Number;
                     63:
                     64:   -- DESCRIPTION :
                     65:   --   Returns the absolute value of f.
                     66:
                     67: -- COMPARISON AND COPYING :
                     68:
                     69:   function Equal ( f1 : Floating_Number; f2 : double_float ) return boolean;
                     70:   function Equal ( f1,f2 : Floating_Number ) return boolean;
                     71:
                     72:   -- DESCRIPTION :
                     73:   --   Returns true if f1 and f2 are equal, false otherwise.
                     74:
                     75:   function "<" ( f1 : double_float; f2 : Floating_Number ) return boolean;
                     76:   function "<" ( f1 : Floating_Number; f2 : double_float ) return boolean;
                     77:   function "<" ( f1,f2 : Floating_Number ) return boolean;
                     78:
                     79:   -- DESCRIPTION :
                     80:   --   Returns true if f1 < f2, false otherwise.
                     81:
                     82:   function ">" ( f1 : double_float; f2 : Floating_Number ) return boolean;
                     83:   function ">" ( f1 : Floating_Number; f2 : double_float ) return boolean;
                     84:   function ">" ( f1,f2 : Floating_Number ) return boolean;
                     85:
                     86:   -- DESCRIPTION :
                     87:   --   Returns true if f1 > f2, false otherwise;
                     88:
                     89:   procedure Copy ( f1 : in Floating_Number; f2 : in out Floating_Number );
                     90:
                     91:   -- DESCRIPTION :
                     92:   --   Clears f2 and copies the content of f1 into f2.
                     93:   --   Note that f2 := f1 leads to data sharing.
                     94:
                     95: -- EXPANDING and SHORTENING THE MANTISSA :
                     96:
                     97:   function  Expand ( f : Floating_Number; k : natural ) return Floating_Number;
                     98:   procedure Expand ( f : in out Floating_Number; k : in natural );
                     99:
                    100:   -- DESCRIPTION :
                    101:   --   Expands the fraction by adding k coefficients.
                    102:
                    103:   function  Round ( f : Floating_Number ) return double_float;
                    104:   function  Round ( f : Floating_Number; k : natural ) return Floating_Number;
                    105:   procedure Round ( f : in out Floating_Number; k : in natural );
                    106:
                    107:   function  Trunc ( f : Floating_Number ) return double_float;
                    108:   function  Trunc ( f : Floating_Number; k : natural ) return Floating_Number;
                    109:   procedure Trunc ( f : in out Floating_Number; k : in natural );
                    110:
                    111:   -- DESCIRPTION :
                    112:   --   Shortens the fraction by removing k coefficients, either by rouding
                    113:   --   or by truncation of the least significant coefficients.
                    114:
                    115:   procedure Set_Size ( f : in out Floating_Number; k : in natural );
                    116:
                    117:   -- DESCRIPTION :
                    118:   --   Sets the size of the floating number f to k, either by rounding
                    119:   --   or expanding its current size.
                    120:
                    121: -- ARITHMETIC OPERATIONS as functions (no data sharing) :
                    122: --   The size of the result is the maximal size of the operands.
                    123:
                    124:   function "+" ( f1 : Floating_Number; f2 : double_float )
                    125:                return Floating_Number;
                    126:   function "+" ( f1 : double_float; f2 : Floating_Number )
                    127:                return Floating_Number;
                    128:   function "+" ( f1,f2 : Floating_Number ) return Floating_Number;
                    129:
                    130:   function "+" ( f : Floating_Number ) return Floating_Number;  -- copy of f
                    131:   function "-" ( f : Floating_Number ) return Floating_Number;
                    132:
                    133:   function "-" ( f1 : Floating_Number; f2 : double_float )
                    134:                return Floating_Number;
                    135:   function "-" ( f1 : double_float; f2 : Floating_Number )
                    136:                return Floating_Number;
                    137:   function "-" ( f1,f2 : Floating_Number ) return Floating_Number;
                    138:
                    139:   function "*" ( f1 : Floating_Number; f2 : double_float )
                    140:                return Floating_Number;
                    141:   function "*" ( f1 : double_float; f2 : Floating_Number )
                    142:                return Floating_Number;
                    143:   function "*" ( f1,f2 : Floating_Number ) return Floating_Number;
                    144:
                    145:   function "**" ( f : double_float; n : Natural_Number ) return Floating_Number;
                    146:   function "**" ( f : Floating_Number; n : Natural_Number )
                    147:                 return Floating_Number;
                    148:
                    149:   function "**" ( f : Floating_Number; i : integer ) return Floating_Number;
                    150:   function "**" ( f : double_float; i : Integer_Number ) return Floating_Number;
                    151:   function "**" ( f : Floating_Number; i : Integer_Number )
                    152:                 return Floating_Number;
                    153:
                    154:   function "/" ( f1 : Floating_Number; f2 : double_float )
                    155:                return Floating_Number;
                    156:   function "/" ( f1 : double_float; f2 : Floating_Number )
                    157:                return Floating_Number;
                    158:   function "/" ( f1,f2 : Floating_Number ) return Floating_Number;
                    159:
                    160: -- ARITHMETIC OPERATIONS as procedures for memory management :
                    161:
                    162:   procedure Add ( f1 : in out Floating_Number; f2 : in double_float );  -- "+"
                    163:   procedure Add ( f1 : in out Floating_Number; f2 : in Floating_Number );
                    164:
                    165:   procedure Sub ( f1 : in out Floating_Number; f2 : in double_float );  -- "-"
                    166:   procedure Sub ( f1 : in out Floating_Number; f2 : in Floating_Number );
                    167:   procedure Min ( f : in out Floating_Number );
                    168:
                    169:   procedure Mul ( f1 : in out Floating_Number; f2 : in double_float );  -- "*"
                    170:   procedure Mul ( f1 : in out Floating_Number; f2 : in Floating_Number );
                    171:
                    172:   procedure Div ( f1 : in out Floating_Number; f2 : in double_float );  -- "/"
                    173:   procedure Div ( f1 : in out Floating_Number; f2 : in Floating_Number );
                    174:
                    175: -- DESTRUCTOR :
                    176:
                    177:   procedure Clear ( f : in out Floating_Number );
                    178:
                    179:   -- DESCRIPTION :
                    180:   --   Deallocations of the occupied memory for f.
                    181:
                    182: private
                    183:
                    184:   type Floating_Number is record
                    185:     fraction,exponent : Integer_Number;
                    186:   end record;
                    187:
                    188: end Multprec_Floating_Numbers;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>