--- ray/src/common/tcos.c 1998/12/16 18:15:07 3.1 +++ ray/src/common/tcos.c 2013/01/17 22:48:21 3.6 @@ -1,9 +1,6 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: tcos.c,v 3.6 2013/01/17 22:48:21 greg Exp $"; #endif - /* * Table-based cosine approximation. * @@ -11,24 +8,23 @@ static char SCCSid[] = "$SunId$ SGI"; * to avoid conversion and guarantee that tsin(x)^2 + tcos(x)^2 == 1. * * No interpolation in this version. + * + * External symbols declared in rtmath.h */ +#include "copyright.h" + #include +#include "rtmath.h" + #ifndef NCOSENTRY -#define NCOSENTRY 256 +#define NCOSENTRY 1024 #endif -#ifdef M_PI -#define PI ((double)M_PI) -#else -#define PI 3.14159265358979323846 -#endif - double -tcos(x) /* approximate cosine */ -register double x; +tcos(double x) /* approximate cosine */ { static double costab[NCOSENTRY+1]; register int i; @@ -40,8 +36,8 @@ register double x; if (x < 0.) x = -x; i = (NCOSENTRY*2./PI) * x + 0.5; - if (i >= 4*NCOSENTRY) - i %= 4*NCOSENTRY; + while (i >= 4*NCOSENTRY) + i -= 4*NCOSENTRY; switch (i / NCOSENTRY) { case 0: return(costab[i]);