
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int sign;
	int exponent;
	int mantissa;
} fc;


fc decompose (float f)
{
	fc a;
	unsigned int i = *(int*)(&f);

	//replace the following three instructions
	a.sign = 0;
	a.exponent = 0;
	a.mantissa = 0;

	return a;
}

// compose a float from its components
float compose (fc a)
{
	unsigned int i;

	// replace the following instruction
	i = 0;

	return *(float*)(&i);
}

// this function should do floating point addition,
// under the assumption that the operands are both positive
fc addition (fc a, fc b)
{
	fc c;
	if (a.sign || b.sign)
	{
		fprintf(stderr,"error: the sign is negetive\n");
		exit(1);
	}

	// innsuring that the exponent of a is the largest
	if (a.exponent < b.exponent) { c = a; a = b; b = c; }

	// insert the correct instructions for the calculation
	// ...

	return c;
}

// display the components of a structure
void display (fc a)
{
	printf("signe = %d, exponent = %d (0x%x), mantissa = %d (0x%x)\n",
		a.sign, a.exponent, a.exponent, a.mantissa, a.mantissa);
}

// main
int main ()
{
	float f,g;
	fc a,b,c;

	printf("Give me a value : ");
	scanf("%f",&f);
	a = decompose(f);
	display(a);
	g = compose(a);
	printf("float value is %f\n",g);

	printf("\nAnd a second : ");
	scanf("%f",&g);
	b = decompose(g);
	display(b);

	printf("\nResult of addition addition:\n");
	c = addition(a,b);
	display(c);
	printf("which represents %f\n",compose(c));
}
