Multiplication Of Two 32-bit Floating Point Values.

Hi,

I am writing a program for multiplication of 32-floating point values. In order to find the significand, I will be dividing the initial number entered by the user by two, can you check if it is programmed correctly.

[CODE]
if (floatingnumber < 0) {sign[0]=1; floatingnumber *= -1;} else {sign[0]=0;}
// printf ("changing to positive bit %f
", floatingnumber);
printf ("
sign bit: %i
", sign[0]);

i=0;
while (floatingnumber !=0) {
floatingnumber *= 0.5;
tempnumber = (floatingnumber * 10);
modulus = tempnumber%10;

if (modulus > 0){temporaryarray[i] = 1;}
else {temporaryarray[i] = 0;}

// printf ("
new digit = %i
", temporaryarray[i]);
floatingnumber -= (modulus/10);
// printf ("
new digit = %f
", floatingnumber);
i +=1;
}
[/CODE]



secondly, i will mutiply the two numbers entered by the user, can you please check if the shift and add algorithm is correct:

[CODE]void multiplysignificands (int mantissa1[24], int mantissa2[24])
{
int finalmantissa[57], mantissa3[57];
int i=0, j=0, k=0;
int shift=57, carry=0;
for (i=0; i<=56; i++) {finalmantissa[i] = 0; mantissa3[i] = 0;}

printf ("
"); for(i=0;i<=23;i++){printf("%i" ,mantissa1[i]);}
printf ("
"); for(i=0;i<=23;i++){printf("%i" ,mantissa2[i]);}

printf ("
multiplying
");

int zero=0;
shift = 0;
for(i=23;i>=0;i--)
{

for(int j=0;j<=23;j++)
{ mantissa3[i+j] = (mantissa1[j] * mantissa2[i]);
printf ("%i", mantissa3[i+j]); }
printf("
multippy: ");
k=0;

for (k=0; k<=56; k++)
{printf ("%i", mantissa3[k]); }
printf ("
after adding array:");

carry=0;
for (k=56; k>=0; k--)
{
if ((mantissa3[k] + finalmantissa[k] + carry) == 0)
{finalmantissa[k] = 0; carry=0;}
else if ((mantissa3[k] + finalmantissa[k] + carry) == 1)
{finalmantissa[k] = 1; carry=0;}
else if ((mantissa3[k] + finalmantissa[k] + carry) == 2)
{finalmantissa[k] = 0 ; carry=1;}
else if ((mantissa3[k] + finalmantissa[k] + carry) == 3)
{finalmantissa[k] = 1 ; carry=1;}
printf ("%i", finalmantissa[k]);
}
printf ("
");
shift +=1;
zero +=1;
}
}
[/CODE]

Note: This is not the complete program.

Comments

  • why don't you check it yourself by testing it with some data to see if the algorithms produce the correct results?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion