#include <stdio.h>
#include <math.h>
#include "../../../libv/include/v_lib.h"

#define	RATIO_EPSILON	1e-6

/*
**	TODO: rewrite it, it performs task by BRUTE FORCE !
*/
double	FindQuotent(double d)
{
	int i;
	double q=1,n;
	/* DUMB !!! */
	for(i=0;i<1000000;i++)	/* How about P6-class CPU ? */
	{
		n=d*q;
		if((n-floor(n))<=RATIO_EPSILON)
			return q;
		q+=1;
	}
	return 1;
}

void	DecimalToNormal(vec_t ratio,vec_t *numerator,vec_t *quotent)
{
	double n,q;
	double sign;
	double r;
	if(ratio<0)
	{
		r=-(double)(ratio);
		sign=-1;
	}
	else
	{
		r=(double)ratio;
		sign=1;
	}
	q=FindQuotent(r);
	n=(r * q);
	*numerator=(vec_t)(sign * n);
	*quotent=(vec_t)q;
}

int main()
{
	vec_t n,q,r;
	r=.11111111;
	DecimalToNormal(r,&n,&q);
	printf("ratio %g, numerator %g, quotent %g\n",r,n,q);
	return 0;
}
