#define _GNU_SOURCE

#include <stdio.h>
#include <math.h>

unsigned mult(unsigned d1, unsigned d2)
{
	unsigned d1_high = d1 >> 16;
	unsigned d1_low = d1 & 65535;
	unsigned d2_high = d2 >> 16;
	unsigned d2_low = d2 & 65535;

	unsigned t = (d1_high * d2_high) << 16;
	t += (d2_low * d1_high);
	t += d1_low * d2_high;
	t += (d1_low * d2_low) >> 16;

	return t;
}

unsigned tofixp(float f)
{
	return f * 65536;
}

float tofp(unsigned d)
{
	return (float)d / 65536;
}

int main(void)
{
	unsigned pi_d = tofixp(M_PIl);
	unsigned e_d = tofixp(M_El);

	printf("pi_d = %f, e_d = %f\n", tofp(pi_d), tofp(e_d));
	printf("pi_d * e_d = %f\n", tofp(mult(pi_d, e_d)));
	printf("pi * e = %f\n", (double)(M_PIl * M_El));

	return 0;
}

