32 bit floating point multiplication

This is a discussion on 32 bit floating point multiplication within the C Programming forums, part of the General Programming Boards category; Hi, I am writing a program for multiplication of 32-floating point values. In order to find the significand, I will ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    9

    Thumbs up 32 bit floating point multiplication

    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\n", floatingnumber);
    	printf ("\nsign bit:         %i\n", 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 ("\nnew digit = %i\n", temporaryarray[i]);
    		floatingnumber -= (modulus/10);
    //		printf ("\nnew digit = %f\n", floatingnumber);
    		i +=1;
    	}


    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 ("\n"); for(i=0;i<=23;i++){printf("%i" ,mantissa1[i]);}
    printf ("\n"); for(i=0;i<=23;i++){printf("%i" ,mantissa2[i]);}
    
    printf ("\nmultiplying\n");
    
    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("\nmultippy:  ");
      k=0;
    
    	for (k=0; k<=56; k++)
    	{printf ("%i", mantissa3[k]);	 }
    	printf ("\nafter 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 ("\n");
    	shift +=1;
    	zero +=1;
    }
    }
    Note: This is not the complete program.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Ill do some really fast wicked 32-bit multiplication for you.

    Code:
    float value1=100.0f;
    float value2=200.0f;
    
    float result=value1*value2;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit or 64 bit allignment ?! gcc options??
    By mynickmynick in forum C Programming
    Replies: 3
    Last Post: 07-29-2008, 02:43 AM
  2. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 11:00 AM
  3. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08:14 PM
  4. 16 bit or 32 bit
    By Juganoo in forum C Programming
    Replies: 9
    Last Post: 12-19-2002, 06:24 AM
  5. 2 questions about floating point and %
    By ams80 in forum C Programming
    Replies: 2
    Last Post: 08-14-2002, 10:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21