Task

Explicitly implement   long multiplication.

This is one possible approach to arbitrary-precision integer algebra.



For output, display the result of    264 * 264.

Optionally, verify your result against builtin arbitrary precision support.

The decimal representation of    264    is:

18,446,744,073,709,551,616

The output of    264 * 264    is    2128,    and is:

340,282,366,920,938,463,463,374,607,431,768,211,456



package Long_Multiplication is
   type Number (<>) is private;
 
   Zero : constant Number;
   One  : constant Number;
 
   function Value (Item : in String) return Number;
   function Image (Item : in Number) return String;
 
   overriding
   function "=" (Left, Right : in Number) return Boolean;
 
   function "+" (Left, Right : in Number) return Number;
   function "*" (Left, Right : in Number) return Number;
 
   function Trim (Item : in Number) return Number;
private
   Bits : constant := 16;
   Base : constant := 2 ** Bits;
 
   type Accumulated_Value is range 0 .. (Base - 1) * Base;
   subtype Digit is Accumulated_Value range 0 .. Base - 1;
 
   type Number is array (Natural range <>) of Digit;
   for Number'Component_Size use Bits; -- or pragma Pack (Number);
 
   Zero : constant Number := (1 .. 0 => 0);
   One  : constant Number := (0 => 1);
 
   procedure Divide (Dividend  : in     Number;
                     Divisor   : in     Digit;
                     Result    :    out Number;
                     Remainder :    out Digit);
end Long_Multiplication;