/*=-=-=-=-=-=-=-=-=-=-  RCCL/RCI Notice of Copyright  -=-=-=-=-=-=-=-=-=-=-=*
 *									    *
 *	Copyright (C) 1987 by all authors described below. Permission to    *
 *	use, distribute and copy is granted, but only for non-commercial    *
 *	purposes and providing the authors are acknowledged and this 	    *
 *	copyright notice is displayed prominently.			    *
 *									    *
 *	The authors provide this software in hope that it will be useful,   *
 *	but do not assume responsibility for its use.			    *
 *									    *
 *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/

/*=~=~=~=~ McGill-Computer-Vision-and-Robotics-Laboratory--C-Module ~=~=~=~=
 *		
 * MODULE NAME:	sin.c
 *
 * DESCRIPTION:	Contains code for the table driven sin_T() routines.
 * 
 * AUTHOR/DATE:	John Lloyd, Fall 1986
 *
 *~=~=~=~=~=~= McGill-Computer-Vision-and-Robotics-Laboratory ~=~=~=~=~=~=*/

#include <math.h>
#include "ctabledefs.h"
#define SIN_IVSIZE (SIN_TBSIZE-2)

float SIN (theta)
double theta;
{
	register float *stp;
	register int index;
	double x;

	index = (x = SIN_TSCALE * theta);
	x -= index;
	stp = (float *) &mt_sin [ index & (SIN_IVSIZE-1) ];

	if (x >= 0.)
	 { return ( stp[3] * x + stp[2] );
	 }
	else
	 { return ( stp[1] * x + stp[2] );
	 }

}

float COS (theta)
float theta;
{
	register float *stp;
	register int index;
	double x;

	index = (x = SIN_TSCALE * theta);
	x -= index;
	stp = (float *) &mt_sin [ (index+SIN_IVSIZE/4) & (SIN_IVSIZE-1) ];

	if (x >= 0.)
	 { return ( stp[3] * x + stp[2] );
	 }
	else
	 { return ( stp[1] * x + stp[2] );
	 }

}

SINCOS (theta, sin, cos)
float theta;
float *sin, *cos;
{
	register float *stp;
	register int index;
	double x;

	index = (x = SIN_TSCALE * theta);
	x -= index;
	stp = (float *) &mt_sin [ index & (SIN_IVSIZE-1) ];

	if (x >= 0.)
	 { *sin = stp[3] * x + stp[2];
	   stp = (float *) &mt_sin [ (index+SIN_IVSIZE/4) & (SIN_IVSIZE-1) ];
	   *cos = stp[3] * x + stp[2];
	 }
	else
	 { *sin = stp[1] * x + stp[2];
	   stp = (float *) &mt_sin [ (index+SIN_IVSIZE/4) & (SIN_IVSIZE-1) ];
	   *cos = stp[1] * x + stp[2];
	 }

}
