#include <iostream.h>
#include <stdio.h>
#include "fixed.h"


void main( void )
{
   // create a bunch of Fixed arrays
   Fixed array1[3][3];
   Fixed array2[3][3];
   Fixed result[3][3];
   Fixed temp,zero_value;

   // Initialize them
   array1[0][0] = array1[1][1] = array1[2][2] =  1;
   array2[0][0] = array2[1][1] = array2[2][2] =  1;


   array1[0][0] =  1;
   array1[0][1] =  3;
   array1[0][2] = -4;

   array1[1][0] = 1;
   array1[1][1] = 1;
   array1[1][2] = -2;

   array1[2][0] = -1;
   array1[2][1] = -2;
   array1[2][2] = 5;



   array2[0][0] = 8;
   array2[1][0] = 3;
   array2[2][0] = 0;

   array2[0][1] = 3;
   array2[1][1] = 10;
   array2[2][1] = 2;

   array2[0][2] = 0;
   array2[1][2] = 2;
   array2[2][2] = 6;

   zero_value = 0;


   // perform a simple matrix multiplication 

   for ( unsigned z = 0 ; z < 100000 ; z ++)
   { // matrix multiply

   for (int i = 0 ; i < 3 ; i++)
      {
      for ( int j = 0 ; j < 3 ; j++)
         {
         temp = zero_value;
         for ( int k = 0 ; k < 3 ; k++)
            {
            // the slow, temporary producing version
//            temp = temp + array1[i][k] * array2[k][j];

            // the much faster, specialized function
            temp.addProduct(array1[i][k],array2[k][j]);
            }
         result[i][j] = temp;
         }
      }
   }


   { // print matrix results

   cout << "\n";

   for ( int i = 0 ; i < 3 ; i++)
      {
      cout << "| " << array1[i][0] << " "
         << array1[i][1] << " "
         << array1[i][2] << " |";
      cout << "| " << array2[i][0] << " "
         << array2[i][1] << " "
         << array2[i][2] << " |";
      cout << "  | " << result[i][0] << " "
         << result[i][1] << " "
         << result[i][2] << " |";

      cout << "\n";
      }

   }
}
