ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/tcos.c
(Generate patch)

Comparing ray/src/common/tcos.c (file contents):
Revision 3.3 by greg, Tue Feb 25 02:47:22 2003 UTC vs.
Revision 3.10 by greg, Fri Jul 12 05:16:02 2013 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9   *
10   * No interpolation in this version.
11   *
12 < * External symbols declared in standard.h
12 > * External symbols declared in rtmath.h
13   */
14  
15   #include "copyright.h"
16  
17   #include <math.h>
18  
19 + #include "rtmath.h"
20 +
21 + #ifndef __FAST_MATH__
22 +
23   #ifndef NCOSENTRY
24 < #define NCOSENTRY       256
24 > #define NCOSENTRY       1024
25   #endif
26  
23 #ifdef M_PI
24 #define PI              ((double)M_PI)
25 #else
26 #define PI              3.14159265358979323846
27 #endif
28
29
27   double
28 < tcos(x)                         /* approximate cosine */
32 < register double x;
28 > tcos(double x)                          /* approximate cosine */
29   {
30          static double   costab[NCOSENTRY+1];
31          register int    i;
# Line 41 | Line 37 | register double        x;
37          if (x < 0.)
38                  x = -x;
39          i = (NCOSENTRY*2./PI) * x  +  0.5;
40 <        if (i >= 4*NCOSENTRY)
41 <                i %= 4*NCOSENTRY;
40 >        while (i >= 4*NCOSENTRY)
41 >                i -= 4*NCOSENTRY;
42          switch (i / NCOSENTRY) {
43          case 0:
44                  return(costab[i]);
# Line 54 | Line 50 | register double        x;
50                  return(costab[(4*NCOSENTRY)-i]);
51          }
52          return(0.);             /* should never be reached */
53 + }
54 +
55 + #endif
56 +
57 + /* Fast arctangent approximation due to Rajan et al. 2006 */
58 + double
59 + atan2a(double y, double x)
60 + {
61 +        double  ratio, aratio, val;
62 +
63 +        if (x == 0)
64 +                return (y > 0) ? PI/2. : 3./2.*PI;
65 +
66 +        aratio = (ratio = y/x) >= 0 ? ratio : -ratio;
67 +
68 +        if (aratio > 1.01)
69 +                return PI/2. - atan2a(x, y);
70 +
71 +        val = PI/4.*ratio - ratio*(aratio - 1.)*(0.2447 + 0.0663*aratio);
72 +
73 +        return val + PI*(x < 0);
74   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines