home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_09
/
1109080b
< prev
next >
Wrap
Text File
|
1993-04-10
|
2KB
|
93 lines
#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";
}
}
}