TABLE OF CONTENTS


Cashe/Cashe [ Packages ]

[ Top ] [ Packages ]

DESCRIPTION

    This package provides datatypes and functions utilized by other packages.

SOURCE

package Cashe is

Cashe/Cashe.Decimal [ Types ]

[ Top ] [ Cashe ] [ Types ]

DESCRIPTION

    128-bit decimal number, ranging from:
    -999_999_999_999_999_999.99999999999999999999 to
    999_999_999_999_999_999.99999999999999999999
    Used for storing the currency.

SOURCE

   type Decimal is delta 1.0E-20 digits 38;

EXAMPLE

   --    My_Dec : Decimal := 1.12345678909876543210;

Cashe/Cashe.Decimal_Major [ Types ]

[ Top ] [ Cashe ] [ Types ]

DESCRIPTION

    Integer number, ranging from:
    -999_999_999_999_999_999 to 999_999_999_999_999_999
    Used for setting major units without precision.

SOURCE

   subtype Decimal_Major is Long_Long_Integer
      range -(1E+18 - 1) .. +(1E+18 - 1);

DERIVED FROM

    Long_Long_Integer

Cashe/Cashe.Decimal_Minor [ Types ]

[ Top ] [ Cashe ] [ Types ]

DESCRIPTION

    128-bit integer number, ranging from:
    -99_999_999_999_999_999_999_999_999_999_999_999_999 to
    99_999_999_999_999_999_999_999_999_999_999_999_999
    Used for setting / accessing minor units

SOURCE

   subtype Decimal_Minor is Long_Long_Long_Integer
      range -(1E+38 - 1) .. +(1E+38 - 1);

DERIVED FROM

    Long_Long_Long_Integer

Cashe/Cashe.Round_Method [ Types ]

[ Top ] [ Cashe ] [ Types ]

DESCRIPTION

    Rounding methods.

SOURCE

   type Round_Method is (
      Half_Even,
      --  Default rounding method, also known as "Banker's Rounding"
      Half_Up
      --  Standard-behavior rounding, the kind taught in highschool.
      );

Cashe/Cashe.Max_Integer_Len [ Constants ]

[ Top ] [ Cashe ] [ Constants ]

DESCRIPTION

    The maximum number of decimal numbers that a major unit can be.

SOURCE

   Max_Integer_Len : constant := 18;

Cashe/Cashe.Max_Precision [ Constants ]

[ Top ] [ Cashe ] [ Constants ]

DESCRIPTION

    The maximum precision that this decimal type has.

SOURCE

   Max_Precision   : constant := 20;

Cashe/Cashe.Minor_Unit_Too_Large [ Exceptions ]

[ Top ] [ Cashe ] [ Exceptions ]

DESCRIPTION

    Raised if the minor unit will not "fit" into the major unit.

SOURCE

   Minor_Unit_Too_Large : exception;

Cashe/Cashe.Round [ Subprograms ]

[ Top ] [ Cashe ] [ Subprograms ]

SOURCE

   function Round
      (Item : Decimal;
       --  The decimal to round
       By : Natural;
       --  The precision which to round to.
       Method : Round_Method := Half_Even
       --  The method of rounding.  Default is Half_Even aka Banker's Rounding.
      )
   return Decimal with pre => By <= Max_Precision;

PARAMETERS

    Item - Decimal to be rounded
    By - Precision to round to.

EXAMPLE

   --    T : Decimal := -2000.005;
   --    A : Decimal := Round (T, 2);          --  -2000.00
   --    B : Decimal := Round (T, 2, Half_Up); --  -2000.01

FUNCTION

    Round the value of a money object to a given precision

RETURN VALUE

    Cashe.Decimal - Decimal value rounded to Precision.

Cashe/Cashe.To_Decimal [ Subprograms ]

[ Top ] [ Cashe ] [ Subprograms ]

ERRORS

    * Cashe/Cashe.Minor_Unit_Too_Large in case of converting Minor Unit

SOURCE

   function To_Decimal
      (Item : Float;
       --  Floating point to be converted to a decimal.
       Precision : Natural := 20
       --  Precision to round to. Default is 20.
      ) return Decimal;
   function To_Decimal
      (Item : Long_Float;
       --  Floating point to be converted to a decimal.
       Precision : Natural := 20
       --  Precision to round to. Default is 20.
      ) return Decimal;
   function To_Decimal
      (Item : Long_Long_Float;
       --  Floating point to be converted to a decimal.
       Precision : Natural := 20
       --  Precision to round to. Default is 20.
       ) return Decimal;
   function To_Decimal
      (Value : Decimal_Minor;
       --  The whole number which to convert into a decimal
       Precision : Natural := 20
       --  The maount of decimal places out
      )
   return Decimal with
      pre => Precision <= Max_Precision;

PARAMETERS

    Item - Floating point to be converted.
    Precision - Precision to round to. Default is 20.

EXAMPLE

   --    with Cashe; use Cashe;
   --    D : Decimal_Minor   :=                1411900
   --    F : Long_Long_Float :=                14.1190004014938372284932918;
   --    A : Decimal := To_Decimal (F);    --  14.11900040149383722880
   --    B : Decimal := To_Decimal (F, 3); --  14.11900000000000000000
   --    C : Decimal := To_Decimal (F, 2); --  14.12000000000000000000
   --    E : Decimal := To_Decimal (D, 5); --  14.11900

FUNCTION

    Convert a floating point number or minor unit to a Decimal based on
    precision.  Highly recommended to use this function with 
    Long_Long_Float for highest precision.

RETURN VALUE

    Cashe.Decimal - Decimal value of float to Precision.