#include <perms.h>

                                                                //      1  ! This is effectively a fixed-point implementation of CORDIC sin and cos which
                                                                //      2  ! checks results against the floating-point library used by C. There are a few
                                                                //      3  ! things we could do to improve accuracy - but this is good enough for a quick
                                                                //      4  ! hack that does not use any external math library code, other than the afore-
                                                                //      5  ! mentioned consistency checks.
                                                                //      6  
                                                                //      7  ! The program is based on Michael Bertrand's CORDIC article which has appeared
                                                                //      8  ! in multiple places including Dr Dobbs magazine, a copy of which can be found
                                                                //      9  ! at http://www.pennelynn.com/Documents/CUJ/HTML/92HTML/1992024C.HTM
                                                                //     10  
                                                                //     11  ! Note that in creating this implementation, we hit a bug that manifested at
                                                                //     12  ! the the extremes of the sin and cos functions (where the values are close
                                                                //     13  ! to 0 or 1) and which I have patched with an approximation since the functions
                                                                //     14  ! are close to linear at those points.  However the hack to correct that error
                                                                //     15  ! does make this code a little larger than the C version from which it was
                                                                //     16  ! derived.
                                                                //     17  
                                                                //     18  ! I have thrown in a local implementation of atan and sqrt for good measure :-)
                                                                //     19  
                                                                //     20  ! Imp77 does not have unsigned integer data types; however since the CORDIC code
                                                                //     21  ! effectively uses a 1.14 fixed point implementation to implement angles (with
                                                                //     22  ! the original C sources being compatible with a 16-bit int environment), and
                                                                //     23  ! the current Imp77 compiler being a 32 bit implementation, unsigned integers
                                                                //     24  ! have not required.
                                                                //     25  
                                                                //     26  %begin
#line 26 "regression-bugs-tmp/cordic32.imp"
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     27  
                                                                //     28  %const %integer debug = 1 { 0 : 4 }
                                                                //     29  
                                                                //     30  !%external %real %fn %spec atan %alias "atanf" (%real angle)  ;! borrow C's math library for use in demo.
                                                                //     31  %real %fn atan(%longreal x1)
#line 31 "regression-bugs-tmp/cordic32.imp"
float ATAN( double X1 )
#line 31 "regression-bugs-tmp/cordic32.imp"
{
                                                                //     32    %const %long %real r1= 1.2595802263029547 @  1
#line 32 "regression-bugs-tmp/cordic32.imp"
const double R1 = 1.2595802263029547E1;
                                                                //     33    %const %long %real r2=-8.6186317517509520 @  1
#line 33 "regression-bugs-tmp/cordic32.imp"
const double R2 = (-8.6186317517509520E1);
                                                                //     34    %const %long %real r3=-1.2766919133361079 @  0
#line 34 "regression-bugs-tmp/cordic32.imp"
const double R3 = (-1.2766919133361079E0);
                                                                //     35    %const %long %real r4=-8.3921038065840512 @ -2
#line 35 "regression-bugs-tmp/cordic32.imp"
const double R4 = (-8.3921038065840512E-2);
                                                                //     36    %const %long %real s1= 2.7096164294378656 @  1
#line 36 "regression-bugs-tmp/cordic32.imp"
const double S1 = 2.7096164294378656E1;
                                                                //     37    %const %long %real s2= 6.5581320451487386 @  0
#line 37 "regression-bugs-tmp/cordic32.imp"
const double S2 = 6.5581320451487386E0;
                                                                //     38    %const %long %real s3= 2.1441643116703661 @  0
#line 38 "regression-bugs-tmp/cordic32.imp"
const double S3 = 2.1441643116703661E0;
                                                                //     39    %const %long %real s4= 1.2676256708212610 @  0
#line 39 "regression-bugs-tmp/cordic32.imp"
const double S4 = 1.2676256708212610E0;
                                                                //     40    %const %long %real rt3= 1.7320508075688772 @  0
#line 40 "regression-bugs-tmp/cordic32.imp"
const double RT3 = 1.7320508075688772E0;
                                                                //     41    %const %long %real piby6= 5.2359877559829887 @ -1
#line 41 "regression-bugs-tmp/cordic32.imp"
const double PIBY6 = 5.2359877559829887E-1;
                                                                //     42    %const %long %real piby2m1= 5.7079632679489661 @ -1
#line 42 "regression-bugs-tmp/cordic32.imp"
const double PIBY2M1 = 5.7079632679489661E-1;
                                                                //     43    %const %long %real rt3m1=7.3205080756887728 @ -1
#line 43 "regression-bugs-tmp/cordic32.imp"
const double RT3M1 = 7.3205080756887728E-1;
                                                                //     44    %const %long %real tanpiby12= 2.6794919243112271 @ -1
#line 44 "regression-bugs-tmp/cordic32.imp"
const double TANPIBY12 = 2.6794919243112271E-1;
                                                                //     45    %long %real xx1,xsq,constant=0
#line 45 "regression-bugs-tmp/cordic32.imp"
double XX1;
#line 45 "regression-bugs-tmp/cordic32.imp"
double XSQ;
#line 45 "regression-bugs-tmp/cordic32.imp"
double CONSTANT;
#line 45 "regression-bugs-tmp/cordic32.imp"
CONSTANT = 0;
                                                                //     46    %integer sign=0,inv=0
#line 46 "regression-bugs-tmp/cordic32.imp"
int SIGN;
#line 46 "regression-bugs-tmp/cordic32.imp"
SIGN = 0;
#line 46 "regression-bugs-tmp/cordic32.imp"
int INV;
#line 46 "regression-bugs-tmp/cordic32.imp"
INV = 0;
                                                                //     47    
                                                                //     48    %if x1<0 %then sign=1 %and xx1=-x1 %else xx1=x1
#line 48 "regression-bugs-tmp/cordic32.imp"
if (((X1) >= (0))) goto L_0002;
#line 48 "regression-bugs-tmp/cordic32.imp"
SIGN = 1;
#line 48 "regression-bugs-tmp/cordic32.imp"
XX1 = (-(X1));
#line 48 "regression-bugs-tmp/cordic32.imp"
goto L_0003;
#line 48 "regression-bugs-tmp/cordic32.imp"
L_0002:;
#line 48 "regression-bugs-tmp/cordic32.imp"
XX1 = X1;
#line 48 "regression-bugs-tmp/cordic32.imp"
L_0003:;
                                                                //     49    %if xx1>1.0 %then xx1=1.0/xx1 %and inv=1
#line 49 "regression-bugs-tmp/cordic32.imp"
if (((XX1) <= (1.0))) goto L_0004;
#line 49 "regression-bugs-tmp/cordic32.imp"
XX1 = (double)((double)((double)(1.0)) / (double)((double)(XX1)));
#line 49 "regression-bugs-tmp/cordic32.imp"
INV = 1;
#line 49 "regression-bugs-tmp/cordic32.imp"
L_0004:;
                                                                //     50    %if xx1>tanpiby12 %then xx1=(rt3m1*xx1-1.0+xx1)/(xx1+rt3) %and constant=piby6
#line 50 "regression-bugs-tmp/cordic32.imp"
if (((XX1) <= (TANPIBY12))) goto L_0005;
#line 50 "regression-bugs-tmp/cordic32.imp"
XX1 = (double)((double)(((((double)((((double)((((double)(RT3M1)) * (XX1)))) - (1.0)))) + (XX1)))) / (double)(((((double)(XX1)) + (RT3)))));
#line 50 "regression-bugs-tmp/cordic32.imp"
CONSTANT = PIBY6;
#line 50 "regression-bugs-tmp/cordic32.imp"
L_0005:;
                                                                //     51    xsq=xx1*xx1
#line 51 "regression-bugs-tmp/cordic32.imp"
XSQ = (((double)(XX1)) * (XX1));
                                                                //     52    xx1 = xx1*(r1/(xsq+s1+r2/(xsq+s2+r3/(xsq+s3+r4/(xsq+s4)))))
#line 52 "regression-bugs-tmp/cordic32.imp"
XX1 = ((XX1) * (((double)((double)((double)(R1)) / (double)(((((((double)(XSQ)) + (S1))) + (((double)((double)((double)(R2)) / (double)(((((((double)(XSQ)) + (S2))) + (((double)((double)((double)(R3)) / (double)(((((((double)(XSQ)) + (S3))) + (((double)((double)((double)(R4)) / (double)(((((double)(XSQ)) + (S4))))))))))))))))))))))))));
                                                                //     53    xx1 = xx1 + constant
#line 53 "regression-bugs-tmp/cordic32.imp"
XX1 = (((double)(XX1)) + (CONSTANT));
                                                                //     54    %if inv=1 %then xx1=1.0-xx1+piby2m1
#line 54 "regression-bugs-tmp/cordic32.imp"
if (((INV) != (1))) goto L_0006;
#line 54 "regression-bugs-tmp/cordic32.imp"
XX1 = (((double)((((double)(1.0)) - (XX1)))) + (PIBY2M1));
#line 54 "regression-bugs-tmp/cordic32.imp"
L_0006:;
                                                                //     55    %if sign=1 %then xx1=-xx1
#line 55 "regression-bugs-tmp/cordic32.imp"
if (((SIGN) != (1))) goto L_0007;
#line 55 "regression-bugs-tmp/cordic32.imp"
XX1 = (-(XX1));
#line 55 "regression-bugs-tmp/cordic32.imp"
L_0007:;
                                                                //     56    %result=xx1 { shorten from %long %real down to %real when returning result }
#line 56 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return XX1;
                                                                //     57  %end
#line 57 "regression-bugs-tmp/cordic32.imp"
} // End of block ATAN at level 2
                                                                //     58  
                                                                //     59  !%external %real %fn %spec sqrt %alias "sqrtf" (%real angle)
                                                                //     60  %real %fn sqrt(%long %real X)
#line 60 "regression-bugs-tmp/cordic32.imp"
float SQRT( double X )
#line 60 "regression-bugs-tmp/cordic32.imp"
{
                                                                //     61    %integer %fn approx integer sqrt(%integer X)
#line 61 "regression-bugs-tmp/cordic32.imp"
int APPROXINTEGERSQRT( int X )
#line 61 "regression-bugs-tmp/cordic32.imp"
{
                                                                //     62      %integer k = 1, result = 1
#line 62 "regression-bugs-tmp/cordic32.imp"
int K;
#line 62 "regression-bugs-tmp/cordic32.imp"
K = 1;
#line 62 "regression-bugs-tmp/cordic32.imp"
int RESULT;
#line 62 "regression-bugs-tmp/cordic32.imp"
RESULT = 1;
                                                                //     63      k = k+1 %and result = k*k %while result <= X
#line 63 "regression-bugs-tmp/cordic32.imp"
L_0008:;
#line 63 "regression-bugs-tmp/cordic32.imp"
if (((RESULT) > (X))) goto L_0009;
#line 63 "regression-bugs-tmp/cordic32.imp"
K = (((int)(K)) + (1));
#line 63 "regression-bugs-tmp/cordic32.imp"
RESULT = (((int)(K)) * (K));
#line 63 "regression-bugs-tmp/cordic32.imp"
goto L_0008;
#line 63 "regression-bugs-tmp/cordic32.imp"
L_0009:;
                                                                //     64      %result = k-1 {note 'off by 1' bug in original C version due to returning k--}
#line 64 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return (((int)(K)) - (1));
                                                                //     65    %end
#line 65 "regression-bugs-tmp/cordic32.imp"
} // End of block APPROXINTEGERSQRT at level 3
                                                                //     66    %integer I
#line 66 "regression-bugs-tmp/cordic32.imp"
int I;
                                                                //     67    %long %real prev A, A, epsilon = X / 100  {accurate enough due to .14 fixed point}
#line 67 "regression-bugs-tmp/cordic32.imp"
double PREVA;
#line 67 "regression-bugs-tmp/cordic32.imp"
double A;
#line 67 "regression-bugs-tmp/cordic32.imp"
double EPSILON;
#line 67 "regression-bugs-tmp/cordic32.imp"
EPSILON = (double)((double)((double)(X)) / (double)((float)(100)));
                                                                //     68    %if X = 2.0 %then %result = 1.41421356237 %else I = approx integer sqrt(INT PT(X))
#line 68 "regression-bugs-tmp/cordic32.imp"
if (((X) != (2.0))) goto L_000b;
#line 68 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return 1.41421356237;
#line 68 "regression-bugs-tmp/cordic32.imp"
L_000b:;
#line 68 "regression-bugs-tmp/cordic32.imp"
I = APPROXINTEGERSQRT(_imp_INTPT(X));
                                                                //     69    %result = I %if X = I*I { exact root }
#line 69 "regression-bugs-tmp/cordic32.imp"
if (((X) != ((((int)(I)) * (I))))) goto L_000c;
#line 69 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return I;
#line 69 "regression-bugs-tmp/cordic32.imp"
L_000c:;
                                                                //     70    ! Newton's method: A{n} = (A{n-1} + X/A{n-1})/2
                                                                //     71    A = I; prev A = A %and A = (A + X/A)/2.0 %until prev A - epsilon <= A %and A <= prev A + epsilon
#line 71 "regression-bugs-tmp/cordic32.imp"
A = I;
#line 71 "regression-bugs-tmp/cordic32.imp"
L_000d:;
#line 71 "regression-bugs-tmp/cordic32.imp"
PREVA = A;
#line 71 "regression-bugs-tmp/cordic32.imp"
A = (double)((double)((((A) + (((double)((double)((double)(X)) / (double)((double)(A)))))))) / (double)((double)(2.0)));
#line 71 "regression-bugs-tmp/cordic32.imp"
if ((((((double)(PREVA)) - (EPSILON))) > (A))) goto L_000f;
#line 71 "regression-bugs-tmp/cordic32.imp"
if (((A) <= ((((double)(PREVA)) + (EPSILON))))) goto L_000e;
#line 71 "regression-bugs-tmp/cordic32.imp"
L_000f:;
#line 71 "regression-bugs-tmp/cordic32.imp"
goto L_000d;
#line 71 "regression-bugs-tmp/cordic32.imp"
L_000e:;
                                                                //     72    %result = A
#line 72 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return A;
                                                                //     73  %end
#line 73 "regression-bugs-tmp/cordic32.imp"
} // End of block SQRT at level 2
/*Warning: potential loss of precision converting from integer AST_ICONST (4 - 4 bytes) to real AST_CALL (ATAN(1) - 4 bytes) detected at ast.c line 108 */
                                                                //     74  
                                                                //     75  %real PI = atan(1) * 4
#line 75 "regression-bugs-tmp/cordic32.imp"
float PI;
#line 75 "regression-bugs-tmp/cordic32.imp"
PI = ((ATAN(1)) * ((float)(4)));
                                                                //     76  
                                                                //     77  %const %integer K64 = 1<<16, K32 = K64>>1, K16 = K32>>1, K8  = K16>>1
                                                                //     78  
                                                                //     79  %routine phex(%integer x)
#line 79 "regression-bugs-tmp/cordic32.imp"
void PHEX( int X )
#line 79 "regression-bugs-tmp/cordic32.imp"
{
                                                                //     80    %own %string (16) hex = "0123456789ABCDEF"
#line 80 "regression-bugs-tmp/cordic32.imp"
static _imp_string /*%string(16)*/ HEX = _imp_str_literal("0123456789ABCDEF");
                                                                //     81    %integer i
#line 81 "regression-bugs-tmp/cordic32.imp"
int I;
                                                                //     82    print symbol(charno(hex, (x >> (i<<2))&15+1)) %for i = 7, -1, 0
#line 82 "regression-bugs-tmp/cordic32.imp"
I = 8;
if ((((0)-(7)) % ((-1))) != 0) _imp_signal(5,1,0,"Illegal cycle I = 7, (-1), 0");
L_0010:;
if (I == 0) goto L_0011;
I += (-1);
#line 82 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSYMBOL(*_imp_CHARNO(&HEX, (((int)((((int)((((unsigned int)(X)) >> (((I) << (2)))))) & (15)))) + (1))));
#line 82 "regression-bugs-tmp/cordic32.imp"
goto L_0010;
#line 82 "regression-bugs-tmp/cordic32.imp"
L_0011:;
                                                                //     83  %end
#line 83 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return;
} // End of block PHEX at level 2
                                                                //     84  
                                                                //     85  %routine SinCos({unsigned} %integer theta, %integer %name sin, %integer %name cos)
#line 85 "regression-bugs-tmp/cordic32.imp"
void SINCOS( int THETA, int /*name*/*SIN, int /*name*/*COS )
#line 85 "regression-bugs-tmp/cordic32.imp"
{
                                                                //     86    %const %integer QUAD1 = 3, QUAD2 = 2, QUAD3 = 0, QUAD4 = 1   { bit 1 for COS x vs -x,  bit 2 for SIN x vs -x }
                                                                //     87    %const %integer NBITS = 14                                   { NBITS is number of bits for CORDIC units. }
                                                                //     88  
                                                                //     89    {unsigned} %const %integer CordicBase = 1 << NBITS                      { base for CORDIC units }
                                                                //     90    {unsigned} %const %integer HalfBase = CordicBase >> 1                   { CordicBase / 2 }
                                                                //     91    {unsigned} %const %integer Quad2Boundary = CordicBase << 1              { 2 * CordicBase }
                                                                //     92    {unsigned} %const %integer Quad3Boundary = CordicBase + Quad2Boundary   { 3 * CordicBase }
                                                                //     93  
                                                                //     94    ! these owns are initialised on the first call to SinCos:
                                                                //     95    %own %integer %array ArcTan(0:NBITS-1)                       { angles for rotation }
#line 95 "regression-bugs-tmp/cordic32.imp"
static int ARCTAN[14];
                                                                //     96    %own %integer xInit                                          { initial x projection }
#line 96 "regression-bugs-tmp/cordic32.imp"
static int XINIT;
                                                                //     97    
                                                                //     98    %integer xcos,xsin  { used to patch a problem that happens near the zeroes and extremes of the results }
#line 98 "regression-bugs-tmp/cordic32.imp"
int XCOS;
#line 98 "regression-bugs-tmp/cordic32.imp"
int XSIN;
                                                                //     99    
                                                                //    100    !  USE : Calc sin and cos with integer CORDIC routine.
                                                                //    101    !  IN  : theta = incoming angle (in CORDIC angle units)
                                                                //    102    !  OUT : sin (in CORDIC fixed point units)
                                                                //    103    !        cos (in CORDIC fixed point units)
                                                                //    104    !  NOTE: The incoming angle theta is in CORDIC angle
                                                                //    105    !        units, which subdivide the circle into 64K parts,
                                                                //    106    !        with 0 deg = 0, 90 deg = 16384 (CordicBase), 180 deg
                                                                //    107    !        = 32768, 270 deg = 49152, etc. The calculated sine
                                                                //    108    !        and cosine are in CORDIC fixed point units - an int
                                                                //    109    !        considered as a fraction of 16384 (CordicBase).
                                                                //    110  
                                                                //    111    %integer quadrant  { quadrant of incoming angle }
#line 111 "regression-bugs-tmp/cordic32.imp"
int QUADRANT;
                                                                //    112    %integer z         { incoming angle moved to 1st quad }
#line 112 "regression-bugs-tmp/cordic32.imp"
int Z;
                                                                //    113    %integer i         { to index rotations - one per bit }
#line 113 "regression-bugs-tmp/cordic32.imp"
int I;
                                                                //    114    %integer x, y      { projections onto axes }
#line 114 "regression-bugs-tmp/cordic32.imp"
int X;
#line 114 "regression-bugs-tmp/cordic32.imp"
int Y;
                                                                //    115    %integer xl, yl    { projections of rotated vector }
#line 115 "regression-bugs-tmp/cordic32.imp"
int XL;
#line 115 "regression-bugs-tmp/cordic32.imp"
int YL;
                                                                //    116  
                                                                //    117    %own %integer initialised = 0
#line 117 "regression-bugs-tmp/cordic32.imp"
static int INITIALISED = 0;
                                                                //    118    %if initialised = 0 %start
#line 118 "regression-bugs-tmp/cordic32.imp"
if (((INITIALISED) != (0))) goto L_0013;
                                                                //    119  
                                                                //    120      !   USE : Load globals used by SinCos().
                                                                //    121      !   OUT : Loads globals used in SinCos() :
                                                                //    122      !    CordicBase    = base for CORDIC units
                                                                //    123      !    HalfBase      = Cordicbase / 2
                                                                //    124      !    Quad2Boundary = 2 * CordicBase
                                                                //    125      !    Quad3Boundary = 3 * CordicBase
                                                                //    126      !    ArcTan()      = the arctans of 1/(2^i)
                                                                //    127      !    xInit         = initial value for x projection
                                                                //    128      !   NOTE: Must be called once only to initialize before
                                                                //    129      !    calling SinCos(). xInit is sufficiently less than
                                                                //    130      !    CordicBase to exactly compensate for the expansion
                                                                //    131      !    in each rotation.
                                                                //    132    
                                                                //    133      {%integer i}      { to index ArcTan() }
                                                                //    134      %real f           { to calc initial x projection }
#line 134 "regression-bugs-tmp/cordic32.imp"
float F;
                                                                //    135      %integer powr     { powers of 2 up to 2^(2*(NBITS-1)) }
#line 135 "regression-bugs-tmp/cordic32.imp"
int POWR;
                                                                //    136    
                                                                //    137      { ArcTans are diminishingly small angles. }
                                                                //    138      powr = 1
#line 138 "regression-bugs-tmp/cordic32.imp"
POWR = 1;
                                                                //    139      %for i = 0, 1, NBITS-1 %cycle
#line 139 "regression-bugs-tmp/cordic32.imp"
I = (-1);
if ((((13)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 13");
L_0014:;
if (I == 13) goto L_0015;
I += 1;
                                                                //    140      
                                                                //    141        ! We could alternatively have created ArcTan as an array of constants at compile time.
                                                                //    142        ArcTan(i) = INT(atan(1.0/powr)/(PI/2.0)*CordicBase)
#line 142 "regression-bugs-tmp/cordic32.imp"
ARCTAN[I] = _imp_INT(((((double)((double)((float)(ATAN(((double)((double)((double)(1.0)) / (double)((float)(POWR))))))) / (double)((((double)((double)((float)(PI)) / (double)((double)(2.0))))))))) * (16384)));
                                                                //    143        %if debug > 1 %start
#line 143 "regression-bugs-tmp/cordic32.imp"
if (((1) <= (1))) goto L_0017;
                                                                //    144          print string("Setting ArcTan("); write(i,0); print string(") to "); phex(ArcTan(i)); newline
#line 144 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Setting ArcTan("));
#line 144 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(I, 0);
#line 144 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(") to "));
#line 144 "regression-bugs-tmp/cordic32.imp"
PHEX(ARCTAN[I]);
#line 144 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    145        %finish
#line 145 "regression-bugs-tmp/cordic32.imp"
L_0017:;
                                                                //    146        powr = powr << 1
#line 146 "regression-bugs-tmp/cordic32.imp"
POWR = ((POWR) << (1));
                                                                //    147        ! xInit is initial value of x projection to compensate for expansions. f = 1/sqrt(2/1 * 5/4 * ...
                                                                //    148        ! Normalize as an NBITS binary fraction (multiply by CordicBase) and store in xInit.
                                                                //    149        ! Get f = 0.607253 and xInit = 9949 = 0x26DD for NBITS = 14.
                                                                //    150      %repeat
#line 150 "regression-bugs-tmp/cordic32.imp"
goto L_0014;
#line 150 "regression-bugs-tmp/cordic32.imp"
L_0015:;
                                                                //    151      f = 1.0
#line 151 "regression-bugs-tmp/cordic32.imp"
F = 1.0;
                                                                //    152  
                                                                //    153      powr = 1
#line 153 "regression-bugs-tmp/cordic32.imp"
POWR = 1;
                                                                //    154      %for i = 0, 1, NBITS-1 %cycle
#line 154 "regression-bugs-tmp/cordic32.imp"
I = (-1);
if ((((13)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 13");
L_0018:;
if (I == 13) goto L_0019;
I += 1;
/*promote*/                                                                //    155        f = (f * (powr + 1)) / powr
#line 155 "regression-bugs-tmp/cordic32.imp"
F = (double)((double)((((F) * ((float)((((int)(POWR)) + (1))))))) / (double)((float)(POWR)));
                                                                //    156        powr = powr << 2
#line 156 "regression-bugs-tmp/cordic32.imp"
POWR = ((POWR) << (2));
                                                                //    157      %repeat
#line 157 "regression-bugs-tmp/cordic32.imp"
goto L_0018;
#line 157 "regression-bugs-tmp/cordic32.imp"
L_0019:;
                                                                //    158  
                                                                //    159      f = 1.0/sqrt(f);              { sqrt is expensive but only done once during initialisation }
#line 159 "regression-bugs-tmp/cordic32.imp"
F = (double)((double)((double)(1.0)) / (double)((float)(SQRT(F))));
/*Warning: potential loss of precision converting from integer AST_ICONST (16384 - 4 bytes) to real AST_VAR (F - 4 bytes) detected at ast.c line 108 */
                                                                //    160                                    { Note could have implemented f = rsqrt(f) instead and been faster }
                                                                //    161                                    
                                                                //    162      xInit = INT(CordicBase * f)   { rounding type conversion to fixed point }
#line 162 "regression-bugs-tmp/cordic32.imp"
XINIT = _imp_INT((((float)(16384)) * (F)));
                                                                //    163      %if debug # 0 %start
#line 163 "regression-bugs-tmp/cordic32.imp"
if (((1) == (0))) goto L_001b;
                                                                //    164        print string("xInit = "); print fl(CordicBase * f, 12)
#line 164 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("xInit = "));
/*Warning: potential loss of precision converting from integer AST_ICONST (16384 - 4 bytes) to real AST_VAR (F - 4 bytes) detected at ast.c line 108 */
#line 164 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTFL((((float)(16384)) * (F)), 12);
                                                                //    165        print string(" = "); write(xInit, 0); newlines(2)
#line 165 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" = "));
#line 165 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(XINIT, 0);
#line 165 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINES(2);
                                                                //    166      %finish
#line 166 "regression-bugs-tmp/cordic32.imp"
L_001b:;
                                                                //    167      
                                                                //    168      initialised = 1
#line 168 "regression-bugs-tmp/cordic32.imp"
INITIALISED = 1;
                                                                //    169    %finish  { initialisation }
#line 169 "regression-bugs-tmp/cordic32.imp"
L_0013:;
                                                                //    170  
                                                                //    171    ! Determine quadrant of incoming angle, translate to 1st quadrant.
                                                                //    172    ! Note use of previously calculated values CordicBase, etc. for speed.
                                                                //    173  
                                                                //    174    theta = theta & (K64-1)  { reduce to a single circle }
#line 174 "regression-bugs-tmp/cordic32.imp"
THETA = ((THETA) & (65535));
                                                                //    175    %if       theta < CordicBase    %then quadrant = QUAD1 %and z = theta                 %c
#line 175 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (16384))) goto L_001c;
#line 175 "regression-bugs-tmp/cordic32.imp"
QUADRANT = 3;
#line 175 "regression-bugs-tmp/cordic32.imp"
Z = THETA;
#line 175 "regression-bugs-tmp/cordic32.imp"
goto L_001d;
#line 175 "regression-bugs-tmp/cordic32.imp"
L_001c:;
#line 175 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (32768))) goto L_001e;
#line 175 "regression-bugs-tmp/cordic32.imp"
QUADRANT = 2;
#line 175 "regression-bugs-tmp/cordic32.imp"
Z = (((int)(32768)) - (THETA));
#line 175 "regression-bugs-tmp/cordic32.imp"
goto L_001d;
#line 175 "regression-bugs-tmp/cordic32.imp"
L_001e:;
#line 175 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (49152))) goto L_001f;
#line 175 "regression-bugs-tmp/cordic32.imp"
QUADRANT = 0;
#line 175 "regression-bugs-tmp/cordic32.imp"
Z = (((int)(THETA)) - (32768));
#line 175 "regression-bugs-tmp/cordic32.imp"
goto L_001d;
#line 175 "regression-bugs-tmp/cordic32.imp"
L_001f:;
#line 175 "regression-bugs-tmp/cordic32.imp"
QUADRANT = 1;
#line 175 "regression-bugs-tmp/cordic32.imp"
Z = (-(THETA));
#line 175 "regression-bugs-tmp/cordic32.imp"
L_001d:;
                                                                //    176    %else %if theta < Quad2Boundary %then quadrant = QUAD2 %and z = Quad2Boundary - theta %c
                                                                //    177    %else %if theta < Quad3Boundary %then quadrant = QUAD3 %and z = theta - Quad2Boundary %c
                                                                //    178    %else                                 quadrant = QUAD4 %and z = -theta
                                                                //    179  
                                                                //    180    ! Initialize projections; Negate z, so same rotations taking angle z to 0 will take (x, y) = (xInit, 0) to (cos, sin).
                                                                //    181    z = z & (K32-1) { this is a bit dodgy on my part as there *are* cases where z is negative above }
#line 181 "regression-bugs-tmp/cordic32.imp"
Z = ((Z) & (32767));
                                                                //    182    x = xInit; y = 0; z = -z
#line 182 "regression-bugs-tmp/cordic32.imp"
X = XINIT;
#line 182 "regression-bugs-tmp/cordic32.imp"
Y = 0;
#line 182 "regression-bugs-tmp/cordic32.imp"
Z = (-(Z));
                                                                //    183  
                                                                //    184    %for i = 0, 1, NBITS-1 %cycle                                                    { Rotate NBITS times. }
#line 184 "regression-bugs-tmp/cordic32.imp"
I = (-1);
if ((((13)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 13");
L_0020:;
if (I == 13) goto L_0021;
I += 1;
                                                                //    185      %if z < 0 %then z = z+ArcTan(i) %and yl = y + (x >> i) %and xl = x - (y >> i)  { Counter-clockwise rotation. } %c
#line 185 "regression-bugs-tmp/cordic32.imp"
if (((Z) >= (0))) goto L_0023;
#line 185 "regression-bugs-tmp/cordic32.imp"
Z = (((int)(Z)) + (ARCTAN[I]));
#line 185 "regression-bugs-tmp/cordic32.imp"
YL = ((Y) + ((int)((int)((((unsigned int)(X)) >> (I))))));
#line 185 "regression-bugs-tmp/cordic32.imp"
XL = ((X) - ((int)((int)((((unsigned int)(Y)) >> (I))))));
#line 185 "regression-bugs-tmp/cordic32.imp"
goto L_0024;
#line 185 "regression-bugs-tmp/cordic32.imp"
L_0023:;
#line 185 "regression-bugs-tmp/cordic32.imp"
Z = (((int)(Z)) - (ARCTAN[I]));
#line 185 "regression-bugs-tmp/cordic32.imp"
YL = ((Y) - ((int)((int)((((unsigned int)(X)) >> (I))))));
#line 185 "regression-bugs-tmp/cordic32.imp"
XL = ((X) + ((int)((int)((((unsigned int)(Y)) >> (I))))));
#line 185 "regression-bugs-tmp/cordic32.imp"
L_0024:;
                                                                //    186      %else z = z-ArcTan(i) %and yl = y - (x >> i) %and xl = x + (y >> i)            { Clockwise rotation. }
                                                                //    187      x = xl; y = yl                                                                 { Put new projections into (x,y) for next go. }
#line 187 "regression-bugs-tmp/cordic32.imp"
X = XL;
#line 187 "regression-bugs-tmp/cordic32.imp"
Y = YL;
                                                                //    188    %repeat
#line 188 "regression-bugs-tmp/cordic32.imp"
goto L_0020;
#line 188 "regression-bugs-tmp/cordic32.imp"
L_0021:;
                                                                //    189  
                                                                //    190    %if quadrant&1 # 0 %then cos = x %else cos = -x  { Attach signs depending on quadrant. }
#line 190 "regression-bugs-tmp/cordic32.imp"
if (((((QUADRANT) & (1))) == (0))) goto L_0025;
#line 190 "regression-bugs-tmp/cordic32.imp"
*COS = X;
#line 190 "regression-bugs-tmp/cordic32.imp"
goto L_0026;
#line 190 "regression-bugs-tmp/cordic32.imp"
L_0025:;
#line 190 "regression-bugs-tmp/cordic32.imp"
*COS = (-(X));
#line 190 "regression-bugs-tmp/cordic32.imp"
L_0026:;
                                                                //    191    %if quadrant&4 # 0 %then sin = y %else sin = -y
#line 191 "regression-bugs-tmp/cordic32.imp"
if (((((QUADRANT) & (4))) == (0))) goto L_0027;
#line 191 "regression-bugs-tmp/cordic32.imp"
*SIN = Y;
#line 191 "regression-bugs-tmp/cordic32.imp"
goto L_0028;
#line 191 "regression-bugs-tmp/cordic32.imp"
L_0027:;
#line 191 "regression-bugs-tmp/cordic32.imp"
*SIN = (-(Y));
#line 191 "regression-bugs-tmp/cordic32.imp"
L_0028:;
                                                                //    192  
                                                                //    193    xsin=sin {debug}
#line 193 "regression-bugs-tmp/cordic32.imp"
XSIN = *SIN;
                                                                //    194    sin = -sin %if Theta < K32
#line 194 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (32768))) goto L_0029;
#line 194 "regression-bugs-tmp/cordic32.imp"
*SIN = (-(*SIN));
#line 194 "regression-bugs-tmp/cordic32.imp"
L_0029:;
                                                                //    195    sin = sin & (K64-1); sin = sin!(\(K16-1)) %if sin > K16
#line 195 "regression-bugs-tmp/cordic32.imp"
*SIN = ((*SIN) & (65535));
#line 195 "regression-bugs-tmp/cordic32.imp"
if (((*SIN) <= (16384))) goto L_002a;
#line 195 "regression-bugs-tmp/cordic32.imp"
*SIN = ((*SIN) | ((~(16383))));
#line 195 "regression-bugs-tmp/cordic32.imp"
L_002a:;
                                                                //    196  
                                                                //    197    xcos=cos {debug}
#line 197 "regression-bugs-tmp/cordic32.imp"
XCOS = *COS;
                                                                //    198    cos = cos & (K64-1); cos = cos!(\(K16-1)) %if cos > K16
#line 198 "regression-bugs-tmp/cordic32.imp"
*COS = ((*COS) & (65535));
#line 198 "regression-bugs-tmp/cordic32.imp"
if (((*COS) <= (16384))) goto L_002b;
#line 198 "regression-bugs-tmp/cordic32.imp"
*COS = ((*COS) | ((~(16383))));
#line 198 "regression-bugs-tmp/cordic32.imp"
L_002b:;
                                                                //    199  
                                                                //    200    %if debug > 1 %start
#line 200 "regression-bugs-tmp/cordic32.imp"
if (((1) <= (1))) goto L_002c;
                                                                //    201      print string("                  Theta ="); write(theta*1608//1024,8)
#line 201 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("                  Theta ="));
#line 201 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(((long)((long)(((((int)(THETA)) * (1608)))) / (long)((int)(1024)))), 8);
                                                                //    202      print string("; SIN(Theta) = "); phex(xsin);
#line 202 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; SIN(Theta) = "));
#line 202 "regression-bugs-tmp/cordic32.imp"
PHEX(XSIN);
                                                                //    203      print string("; COS(Theta) = "); phex(xcos);
#line 203 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; COS(Theta) = "));
#line 203 "regression-bugs-tmp/cordic32.imp"
PHEX(XCOS);
                                                                //    204      newline
#line 204 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    205    %finish
#line 205 "regression-bugs-tmp/cordic32.imp"
L_002c:;
                                                                //    206  
                                                                //    207    ! There is a bug in this implementation that fails near multiples of 90 degrees -
                                                                //    208    ! this test catches the broken cases and uses an approximation to repair the results :-(
                                                                //    209    ! I will remove these hacks later, if I ever find and fix the bug properly!
                                                                //    210    ! My suspicion is of overflow of a partial 16x16 multiplication somewhere, or maybe a '<<'.
                                                                //    211    %if xsin&16_FFFFC000 # 16_FFFFC000 %and xsin&16_FFFFC000 # 0 %then %start
#line 211 "regression-bugs-tmp/cordic32.imp"
if (((((XSIN) & ((-16384)))) == ((-16384)))) goto L_002d;
#line 211 "regression-bugs-tmp/cordic32.imp"
if (((((XSIN) & ((-16384)))) == (0))) goto L_002d;
                                                                //    212      %if                  theta < 16_0400 %start
#line 212 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (1024))) goto L_002e;
                                                                //    213        sin = theta*1608//1024
#line 213 "regression-bugs-tmp/cordic32.imp"
*SIN = (long)((long)(((((int)(THETA)) * (1608)))) / (long)((int)(1024)));
                                                                //    214      %else %if 16_3C00 <= theta < 16_4000
#line 214 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 214 "regression-bugs-tmp/cordic32.imp"
L_002e:;
#line 214 "regression-bugs-tmp/cordic32.imp"
if ((((15360) > (THETA))) || (((THETA) >= (16384)))) goto L_0030;
                                                                //    215        sin = K16 - (16_4000-theta)//25
#line 215 "regression-bugs-tmp/cordic32.imp"
*SIN = ((16384) - (((long)((long)(((((int)(16384)) - (THETA)))) / (long)((int)(25))))));
                                                                //    216      %else %if 16_4000 <= theta < 16_4400
#line 216 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 216 "regression-bugs-tmp/cordic32.imp"
L_0030:;
#line 216 "regression-bugs-tmp/cordic32.imp"
if ((((16384) > (THETA))) || (((THETA) >= (17408)))) goto L_0031;
                                                                //    217        sin = K16 - (theta-16_4000)//25
#line 217 "regression-bugs-tmp/cordic32.imp"
*SIN = ((16384) - (((long)((long)(((((int)(THETA)) - (16384)))) / (long)((int)(25))))));
                                                                //    218      %else %if 16_7C00 <= theta < 16_8400
#line 218 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 218 "regression-bugs-tmp/cordic32.imp"
L_0031:;
#line 218 "regression-bugs-tmp/cordic32.imp"
if ((((31744) > (THETA))) || (((THETA) >= (33792)))) goto L_0032;
                                                                //    219        sin = (16_8000-theta)*1608//1024
#line 219 "regression-bugs-tmp/cordic32.imp"
*SIN = (long)((long)(((((int)((((int)(32768)) - (THETA)))) * (1608)))) / (long)((int)(1024)));
                                                                //    220      %else %if 16_BC00 <= theta < 16_C000
#line 220 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 220 "regression-bugs-tmp/cordic32.imp"
L_0032:;
#line 220 "regression-bugs-tmp/cordic32.imp"
if ((((48128) > (THETA))) || (((THETA) >= (49152)))) goto L_0033;
                                                                //    221        sin = -K16 + (16_C000-theta)//25
#line 221 "regression-bugs-tmp/cordic32.imp"
*SIN = (((-16384)) + (((long)((long)(((((int)(49152)) - (THETA)))) / (long)((int)(25))))));
                                                                //    222      %else %if 16_C000 <= theta < 16_C400
#line 222 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 222 "regression-bugs-tmp/cordic32.imp"
L_0033:;
#line 222 "regression-bugs-tmp/cordic32.imp"
if ((((49152) > (THETA))) || (((THETA) >= (50176)))) goto L_0034;
                                                                //    223        sin = -K16 + (theta-16_C000)//25
#line 223 "regression-bugs-tmp/cordic32.imp"
*SIN = (((-16384)) + (((long)((long)(((((int)(THETA)) - (49152)))) / (long)((int)(25))))));
                                                                //    224      %else %if 16_FC00 <= theta
#line 224 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 224 "regression-bugs-tmp/cordic32.imp"
L_0034:;
#line 224 "regression-bugs-tmp/cordic32.imp"
if (((64512) > (THETA))) goto L_0035;
                                                                //    225        sin = -(16_10000-theta)*1608//1024
#line 225 "regression-bugs-tmp/cordic32.imp"
*SIN = (-(((long)((long)(((((int)((((int)(65536)) - (THETA)))) * (1608)))) / (long)((int)(1024))))));
                                                                //    226      %else
#line 226 "regression-bugs-tmp/cordic32.imp"
goto L_002f;
#line 226 "regression-bugs-tmp/cordic32.imp"
L_0035:;
                                                                //    227        print string("Oops, missed a case: sin "); phex(theta); newline; %stop
#line 227 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Oops, missed a case: sin "));
#line 227 "regression-bugs-tmp/cordic32.imp"
PHEX(THETA);
#line 227 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
#line 227 "regression-bugs-tmp/cordic32.imp"
exit(0);
                                                                //    228      %finish
#line 228 "regression-bugs-tmp/cordic32.imp"
L_002f:;
                                                                //    229    %finish
#line 229 "regression-bugs-tmp/cordic32.imp"
L_002d:;
                                                                //    230    
                                                                //    231    %if xcos&16_FFFFC000 # 16_FFFFC000 %and xcos&16_FFFFC000 # 0 %then %start
#line 231 "regression-bugs-tmp/cordic32.imp"
if (((((XCOS) & ((-16384)))) == ((-16384)))) goto L_0036;
#line 231 "regression-bugs-tmp/cordic32.imp"
if (((((XCOS) & ((-16384)))) == (0))) goto L_0036;
                                                                //    232      %if                  theta < 16_0400 %start
#line 232 "regression-bugs-tmp/cordic32.imp"
if (((THETA) >= (1024))) goto L_0037;
                                                                //    233        cos = K16 - (theta)//25
#line 233 "regression-bugs-tmp/cordic32.imp"
*COS = ((16384) - (((long)((long)((int)(THETA)) / (long)((int)(25))))));
                                                                //    234      %else %if 16_3C00 <= theta < 16_4400
#line 234 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 234 "regression-bugs-tmp/cordic32.imp"
L_0037:;
#line 234 "regression-bugs-tmp/cordic32.imp"
if ((((15360) > (THETA))) || (((THETA) >= (17408)))) goto L_0039;
                                                                //    235        cos = (16_4000-theta)*1608//1024
#line 235 "regression-bugs-tmp/cordic32.imp"
*COS = (long)((long)(((((int)((((int)(16384)) - (THETA)))) * (1608)))) / (long)((int)(1024)));
                                                                //    236      %else %if 16_7C00 <= theta < 16_8000
#line 236 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 236 "regression-bugs-tmp/cordic32.imp"
L_0039:;
#line 236 "regression-bugs-tmp/cordic32.imp"
if ((((31744) > (THETA))) || (((THETA) >= (32768)))) goto L_003a;
                                                                //    237        cos = -K16 + (16_8000-theta)//25
#line 237 "regression-bugs-tmp/cordic32.imp"
*COS = (((-16384)) + (((long)((long)(((((int)(32768)) - (THETA)))) / (long)((int)(25))))));
                                                                //    238      %else %if 16_8000 <= theta < 16_8400
#line 238 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 238 "regression-bugs-tmp/cordic32.imp"
L_003a:;
#line 238 "regression-bugs-tmp/cordic32.imp"
if ((((32768) > (THETA))) || (((THETA) >= (33792)))) goto L_003b;
                                                                //    239        cos = -K16 + (theta-16_8000)//25
#line 239 "regression-bugs-tmp/cordic32.imp"
*COS = (((-16384)) + (((long)((long)(((((int)(THETA)) - (32768)))) / (long)((int)(25))))));
                                                                //    240      %else %if 16_BC00 <= theta < 16_C400
#line 240 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 240 "regression-bugs-tmp/cordic32.imp"
L_003b:;
#line 240 "regression-bugs-tmp/cordic32.imp"
if ((((48128) > (THETA))) || (((THETA) >= (50176)))) goto L_003c;
                                                                //    241        cos = (theta-16_C000)*1608//1024
#line 241 "regression-bugs-tmp/cordic32.imp"
*COS = (long)((long)(((((int)((((int)(THETA)) - (49152)))) * (1608)))) / (long)((int)(1024)));
                                                                //    242      %else %if 16_FC00 <= theta
#line 242 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 242 "regression-bugs-tmp/cordic32.imp"
L_003c:;
#line 242 "regression-bugs-tmp/cordic32.imp"
if (((64512) > (THETA))) goto L_003d;
                                                                //    243        cos = K16 - (16_10000-theta)//25
#line 243 "regression-bugs-tmp/cordic32.imp"
*COS = ((16384) - (((long)((long)(((((int)(65536)) - (THETA)))) / (long)((int)(25))))));
                                                                //    244      %else
#line 244 "regression-bugs-tmp/cordic32.imp"
goto L_0038;
#line 244 "regression-bugs-tmp/cordic32.imp"
L_003d:;
                                                                //    245        print string("Oops, missed a case: cos "); phex(theta); newline; %stop
#line 245 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Oops, missed a case: cos "));
#line 245 "regression-bugs-tmp/cordic32.imp"
PHEX(THETA);
#line 245 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
#line 245 "regression-bugs-tmp/cordic32.imp"
exit(0);
                                                                //    246      %finish
#line 246 "regression-bugs-tmp/cordic32.imp"
L_0038:;
                                                                //    247    %finish
#line 247 "regression-bugs-tmp/cordic32.imp"
L_0036:;
                                                                //    248  %end
#line 248 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return;
} // End of block SINCOS at level 2
                                                                //    249  
                                                                //    250  !%external %real %fn %spec sin %alias "sinf" (%real angle)  ;! use C's math lib to check results.
                                                                //    251  !%external %real %fn %spec cos %alias "cosf" (%real angle)
                                                                //    252  
                                                                //    253  %real Theta
#line 253 "regression-bugs-tmp/cordic32.imp"
float THETA;
                                                                //    254  %integer i, sinTheta, cosTheta, CheckSinTheta, CheckCosTheta, sinErr = 0, cosErr = 0, err
#line 254 "regression-bugs-tmp/cordic32.imp"
int I;
#line 254 "regression-bugs-tmp/cordic32.imp"
int SINTHETA;
#line 254 "regression-bugs-tmp/cordic32.imp"
int COSTHETA;
#line 254 "regression-bugs-tmp/cordic32.imp"
int CHECKSINTHETA;
#line 254 "regression-bugs-tmp/cordic32.imp"
int CHECKCOSTHETA;
#line 254 "regression-bugs-tmp/cordic32.imp"
int SINERR;
#line 254 "regression-bugs-tmp/cordic32.imp"
SINERR = 0;
#line 254 "regression-bugs-tmp/cordic32.imp"
int COSERR;
#line 254 "regression-bugs-tmp/cordic32.imp"
COSERR = 0;
#line 254 "regression-bugs-tmp/cordic32.imp"
int ERR;
                                                                //    255  
                                                                //    256  %routine pround(%integer f, n)
#line 256 "regression-bugs-tmp/cordic32.imp"
void PROUND( int F, int N )
#line 256 "regression-bugs-tmp/cordic32.imp"
{
                                                                //    257    ! This is a quick (and rather ugly) hack due to the current Imp compiler
                                                                //    258    ! not implementing all of the usual floating point I/O library calls yet
                                                                //    259    
                                                                //    260    %real r, sign = 1.0
#line 260 "regression-bugs-tmp/cordic32.imp"
float R;
#line 260 "regression-bugs-tmp/cordic32.imp"
float SIGN;
#line 260 "regression-bugs-tmp/cordic32.imp"
SIGN = 1.0;
                                                                //    261    %integer tens = 0, p
#line 261 "regression-bugs-tmp/cordic32.imp"
int TENS;
#line 261 "regression-bugs-tmp/cordic32.imp"
TENS = 0;
#line 261 "regression-bugs-tmp/cordic32.imp"
int P;
                                                                //    262  
                                                                //    263    %if f=0 %start
#line 263 "regression-bugs-tmp/cordic32.imp"
if (((F) != (0))) goto L_003e;
                                                                //    264      r = 0
#line 264 "regression-bugs-tmp/cordic32.imp"
R = 0;
                                                                //    265    %else
#line 265 "regression-bugs-tmp/cordic32.imp"
goto L_003f;
#line 265 "regression-bugs-tmp/cordic32.imp"
L_003e:;
                                                                //    266      f = -f %and sign = -1.0 %if f < 0
#line 266 "regression-bugs-tmp/cordic32.imp"
if (((F) >= (0))) goto L_0040;
#line 266 "regression-bugs-tmp/cordic32.imp"
F = (-(F));
#line 266 "regression-bugs-tmp/cordic32.imp"
SIGN = (-1.0);
#line 266 "regression-bugs-tmp/cordic32.imp"
L_0040:;
                                                                //    267      r = f / K16
#line 267 "regression-bugs-tmp/cordic32.imp"
R = (double)((double)((float)(F)) / (double)((float)(16384)));
                                                                //    268      r = r * 10.0 %and tens = tens+1 %until 100 <= INT PT(r) < 1000
#line 268 "regression-bugs-tmp/cordic32.imp"
L_0041:;
#line 268 "regression-bugs-tmp/cordic32.imp"
R = (((double)(R)) * (10.0));
#line 268 "regression-bugs-tmp/cordic32.imp"
TENS = (((int)(TENS)) + (1));
#line 268 "regression-bugs-tmp/cordic32.imp"
if (({int tmp1 = 100, tmp2 = _imp_INTPT(R), tmp3 = 1000; (tmp1 > tmp2) || (tmp2 < tmp3);})) goto L_0042;
#line 268 "regression-bugs-tmp/cordic32.imp"
L_0043:;
#line 268 "regression-bugs-tmp/cordic32.imp"
goto L_0041;
#line 268 "regression-bugs-tmp/cordic32.imp"
L_0042:;
                                                                //    269      p = tens
#line 269 "regression-bugs-tmp/cordic32.imp"
P = TENS;
                                                                //    270      r = INT(r)  { round to 3 significant digits }
#line 270 "regression-bugs-tmp/cordic32.imp"
R = _imp_INT(R);
                                                                //    271      r = r / 10.0 %and tens = tens-1 %while tens > 0
#line 271 "regression-bugs-tmp/cordic32.imp"
L_0044:;
#line 271 "regression-bugs-tmp/cordic32.imp"
if (((TENS) <= (0))) goto L_0045;
#line 271 "regression-bugs-tmp/cordic32.imp"
R = (double)((double)((float)(R)) / (double)((double)(10.0)));
#line 271 "regression-bugs-tmp/cordic32.imp"
TENS = (((int)(TENS)) - (1));
#line 271 "regression-bugs-tmp/cordic32.imp"
goto L_0044;
#line 271 "regression-bugs-tmp/cordic32.imp"
L_0045:;
                                                                //    272      r = r + 0.000001 { handle real values not exactly representable in decimal }
#line 272 "regression-bugs-tmp/cordic32.imp"
R = (((double)(R)) + (0.000001));
                                                                //    273    %finish
#line 273 "regression-bugs-tmp/cordic32.imp"
L_003f:;
                                                                //    274    spaces(n - (p+3))
#line 274 "regression-bugs-tmp/cordic32.imp"
_imp_SPACES(((N) - ((int)((((int)(P)) + (3))))));
                                                                //    275    %if sign < 0 %then print symbol('-') %else print symbol(' ')
#line 275 "regression-bugs-tmp/cordic32.imp"
if (((SIGN) >= (0))) goto L_0047;
#line 275 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSYMBOL(45);
#line 275 "regression-bugs-tmp/cordic32.imp"
goto L_0048;
#line 275 "regression-bugs-tmp/cordic32.imp"
L_0047:;
#line 275 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSYMBOL(32);
#line 275 "regression-bugs-tmp/cordic32.imp"
L_0048:;
                                                                //    276    print fl(r, p+2) { library call truncates, doesn't round :-( }
#line 276 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTFL(R, (((int)(P)) + (2)));
                                                                //    277  %end
#line 277 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return;
} // End of block PROUND at level 2
                                                                //    278  
                                                                //    279  %on %event * %start
#line 279 "regression-bugs-tmp/cordic32.imp"
if (!_imp_on_event(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) goto L_0049;  /* TO DO: Remove %on %event handler just before L_0049: if present for this block */
                                                                //    280    newline
#line 280 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    281    %if event_event = 14 %and event_sub{event} = 1 %start
#line 281 "regression-bugs-tmp/cordic32.imp"
if (((_imp_EVENT().EVENT) != (14))) goto L_004a;
#line 281 "regression-bugs-tmp/cordic32.imp"
if (((_imp_EVENT().SUB) != (1))) goto L_004a;
                                                                //    282      ! These are generated outside of the Imp77 environment, such as by Valgrind or GCC's Undefined Behaviour detection (ubsan).
                                                                //    283      %if event_info{extra} = 4 %start
#line 283 "regression-bugs-tmp/cordic32.imp"
if (((_imp_EVENT().INFO) != (4))) goto L_004b;
                                                                //    284        ! SIGILL
                                                                //    285        print string("Linux Signal SIGILL trapped at ")
#line 285 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Linux Signal SIGILL trapped at "));
                                                                //    286        print string(event file)
#line 286 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_EVENTFILE());
                                                                //    287        print string(" line")
#line 287 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" line"));
                                                                //    288        write(event line, 0)
#line 288 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENTLINE(), 0);
                                                                //    289        print string(" - this was probably raised by ubsan (gcc -fsanitize-trap=undefined)")
#line 289 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" - this was probably raised by ubsan (gcc -fsanitize-trap=undefined)"));
                                                                //    290        newline
#line 290 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    291      %else %if event_info{extra} = 8
#line 291 "regression-bugs-tmp/cordic32.imp"
goto L_004c;
#line 291 "regression-bugs-tmp/cordic32.imp"
L_004b:;
#line 291 "regression-bugs-tmp/cordic32.imp"
if (((_imp_EVENT().INFO) != (8))) goto L_004d;
                                                                //    292        ! SIGFPE
                                                                //    293        print string("Linux Signal SIGFPE trapped at ")
#line 293 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Linux Signal SIGFPE trapped at "));
                                                                //    294        print string(event file)
#line 294 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_EVENTFILE());
                                                                //    295        print string(" line")
#line 295 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" line"));
                                                                //    296        write(event line, 0)
#line 296 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENTLINE(), 0);
                                                                //    297        print string(" - this is a floating point error (such as divide by zero)")
#line 297 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" - this is a floating point error (such as divide by zero)"));
                                                                //    298        newline
#line 298 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    299      %else %if event_info{extra} = 8
#line 299 "regression-bugs-tmp/cordic32.imp"
goto L_004c;
#line 299 "regression-bugs-tmp/cordic32.imp"
L_004d:;
#line 299 "regression-bugs-tmp/cordic32.imp"
if (((_imp_EVENT().INFO) != (8))) goto L_004e;
                                                                //    300        ! SIGSEGV
                                                                //    301        print string("Linux Signal SIGSEGV trapped at ")
#line 301 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Linux Signal SIGSEGV trapped at "));
                                                                //    302        print string(event file)
#line 302 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_EVENTFILE());
                                                                //    303        print string(" line")
#line 303 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" line"));
                                                                //    304        write(event line, 0)
#line 304 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENTLINE(), 0);
                                                                //    305        print string(" - this may be from a NULL pointer or accessing past the end of an array")
#line 305 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" - this may be from a NULL pointer or accessing past the end of an array"));
                                                                //    306        newline
#line 306 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    307      %else
#line 307 "regression-bugs-tmp/cordic32.imp"
goto L_004c;
#line 307 "regression-bugs-tmp/cordic32.imp"
L_004e:;
                                                                //    308        ! unknown
                                                                //    309        print string("Linux Signal "); write(event_info{extra}, 0); print string(" trapped."); newlines(2)
#line 309 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Linux Signal "));
#line 309 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENT().INFO, 0);
#line 309 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" trapped."));
#line 309 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINES(2);
                                                                //    310      %finish
#line 310 "regression-bugs-tmp/cordic32.imp"
L_004c:;
                                                                //    311    %else
#line 311 "regression-bugs-tmp/cordic32.imp"
goto L_004f;
#line 311 "regression-bugs-tmp/cordic32.imp"
L_004a:;
                                                                //    312      print string("Imp77 %signal ")
#line 312 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Imp77 %signal "));
                                                                //    313      write(event_event,0); print string(", ")
#line 313 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENT().EVENT, 0);
#line 313 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(", "));
                                                                //    314      write(event_sub{event},0); print string(", ")
#line 314 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENT().SUB, 0);
#line 314 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(", "));
                                                                //    315      write(event_info{extra},0)
#line 315 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENT().INFO, 0);
                                                                //    316      print string(" raised in ")
#line 316 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" raised in "));
                                                                //    317      print string(event file)
#line 317 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_EVENTFILE());
                                                                //    318      print string(" line")
#line 318 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(" line"));
                                                                //    319      write(event line, 0)
#line 319 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(_imp_EVENTLINE(), 0);
                                                                //    320      newline
#line 320 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    321    %finish
#line 321 "regression-bugs-tmp/cordic32.imp"
L_004f:;
                                                                //    322    print string(event message)
#line 322 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_EVENTMESSAGE());
                                                                //    323    %stop
#line 323 "regression-bugs-tmp/cordic32.imp"
exit(0);
                                                                //    324  %finish
#line 324 "regression-bugs-tmp/cordic32.imp"
L_0049:;
                                                                //    325  
                                                                //    326    ! We get about 3 significant digits of accuracy
                                                                //    327    print string("Note: this CORDIC was implemented to only 14 bits of accuracy for 16 bit machines,"); newline
#line 327 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Note: this CORDIC was implemented to only 14 bits of accuracy for 16 bit machines,"));
#line 327 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    328    print string("      so we will report results to 3 significant digits."); newlines(2)
#line 328 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("      so we will report results to 3 significant digits."));
#line 328 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINES(2);
/*Warning: potential loss of precision converting from integer AST_ICONST (2 - 4 bytes) to real AST_VAR (PI - 4 bytes) detected at ast.c line 108 */
                                                                //    329    
                                                                //    330    SinCos(INT(-9*K64/(2*PI)), sinTheta, cosTheta)
#line 330 "regression-bugs-tmp/cordic32.imp"
SINCOS(_imp_INT((-(((double)((double)(((((int)(9)) * (65536)))) / (double)(((((float)(2)) * (PI))))))))), &SINTHETA, &COSTHETA);
                                                                //    331    printstring("sin and cos of  -9 is "); pround(sinTheta,6); space; pround(cosTheta,6); newline
#line 331 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("sin and cos of  -9 is "));
#line 331 "regression-bugs-tmp/cordic32.imp"
PROUND(SINTHETA, 6);
#line 331 "regression-bugs-tmp/cordic32.imp"
_imp_SPACE();
#line 331 "regression-bugs-tmp/cordic32.imp"
PROUND(COSTHETA, 6);
#line 331 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
/*Warning: potential loss of precision converting from integer AST_ICONST (2 - 4 bytes) to real AST_VAR (PI - 4 bytes) detected at ast.c line 108 */
                                                                //    332  
                                                                //    333    SinCos(INT(0*K64/(2*PI)), sinTheta, cosTheta)
#line 333 "regression-bugs-tmp/cordic32.imp"
SINCOS(_imp_INT(((double)((double)(((((int)(0)) * (65536)))) / (double)(((((float)(2)) * (PI))))))), &SINTHETA, &COSTHETA);
                                                                //    334    printstring("sin and cos of   0 is "); pround(sinTheta,6); space; pround(cosTheta,6); newline
#line 334 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("sin and cos of   0 is "));
#line 334 "regression-bugs-tmp/cordic32.imp"
PROUND(SINTHETA, 6);
#line 334 "regression-bugs-tmp/cordic32.imp"
_imp_SPACE();
#line 334 "regression-bugs-tmp/cordic32.imp"
PROUND(COSTHETA, 6);
#line 334 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
/*promote*//*Warning: potential loss of precision converting from integer AST_ICONST (2 - 4 bytes) to real AST_VAR (PI - 4 bytes) detected at ast.c line 108 */
                                                                //    335  
                                                                //    336    SinCos(INT(1.5*K64/(2*PI)), sinTheta, cosTheta)
#line 336 "regression-bugs-tmp/cordic32.imp"
SINCOS(_imp_INT(((double)((double)((((1.5) * ((double)(65536))))) / (double)(((((float)(2)) * (PI))))))), &SINTHETA, &COSTHETA);
                                                                //    337    printstring("sin and cos of 1.5 is "); pround(sinTheta,6); space; pround(cosTheta,6); newline
#line 337 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("sin and cos of 1.5 is "));
#line 337 "regression-bugs-tmp/cordic32.imp"
PROUND(SINTHETA, 6);
#line 337 "regression-bugs-tmp/cordic32.imp"
_imp_SPACE();
#line 337 "regression-bugs-tmp/cordic32.imp"
PROUND(COSTHETA, 6);
#line 337 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
/*Warning: potential loss of precision converting from integer AST_ICONST (2 - 4 bytes) to real AST_VAR (PI - 4 bytes) detected at ast.c line 108 */
                                                                //    338  
                                                                //    339    SinCos(INT(6*K64/(2*PI)), sinTheta, cosTheta)
#line 339 "regression-bugs-tmp/cordic32.imp"
SINCOS(_imp_INT(((double)((double)(((((int)(6)) * (65536)))) / (double)(((((float)(2)) * (PI))))))), &SINTHETA, &COSTHETA);
                                                                //    340    printstring("sin and cos of   6 is "); pround(sinTheta,6); space; pround(cosTheta,6); newline
#line 340 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("sin and cos of   6 is "));
#line 340 "regression-bugs-tmp/cordic32.imp"
PROUND(SINTHETA, 6);
#line 340 "regression-bugs-tmp/cordic32.imp"
_imp_SPACE();
#line 340 "regression-bugs-tmp/cordic32.imp"
PROUND(COSTHETA, 6);
#line 340 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    341  
                                                                //    342  
                                                                //    343    %if debug # 0 %start
#line 343 "regression-bugs-tmp/cordic32.imp"
if (((1) == (0))) goto L_0050;
                                                                //    344      %for i = 0, 4096, K64 %cycle  { A circle is 64K units }
#line 344 "regression-bugs-tmp/cordic32.imp"
I = (-4096);
if ((((65536)-(0)) % (4096)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 4096, 65536");
L_0051:;
if (I == 65536) goto L_0052;
I += 4096;
/*promote*/                                                                //    345        Theta = i*2*PI/K64 { A circle is 2Pi radians }
#line 345 "regression-bugs-tmp/cordic32.imp"
THETA = (double)((double)(((((float)((((int)(I)) * (2)))) * (PI)))) / (double)((float)(65536)));
                                                                //    346    
                                                                //    347        SinCos(i, sinTheta, cosTheta)
#line 347 "regression-bugs-tmp/cordic32.imp"
SINCOS(I, &SINTHETA, &COSTHETA);
                                                                //    348    
                                                                //    349        print string("Cordic:         Theta = "); phex(i)
#line 349 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Cordic:         Theta = "));
#line 349 "regression-bugs-tmp/cordic32.imp"
PHEX(I);
                                                                //    350        print string("; Sin(Theta) = "); write(sinTheta, 0)
#line 350 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; Sin(Theta) = "));
#line 350 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(SINTHETA, 0);
                                                                //    351        print string("; Cos(Theta) = "); write(cosTheta, 0)
#line 351 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; Cos(Theta) = "));
#line 351 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(COSTHETA, 0);
                                                                //    352        newline;
#line 352 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
/*promote*/                                                                //    353        
                                                                //    354        CheckSinTheta = INT(sin(Theta)*K16); CheckCosTheta = INT(cos(Theta)*K16);
#line 354 "regression-bugs-tmp/cordic32.imp"
CHECKSINTHETA = _imp_INT(((_imp_SIN(THETA)) * ((double)(16384))));
/*promote*/#line 354 "regression-bugs-tmp/cordic32.imp"
CHECKCOSTHETA = _imp_INT(((_imp_COS(THETA)) * ((double)(16384))));
                                                                //    355        
                                                                //    356        print string("Floating point: Theta = "); phex(INT(Theta/(2*PI)*K64))
#line 356 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Floating point: Theta = "));
/*Warning: potential loss of precision converting from integer AST_ICONST (2 - 4 bytes) to real AST_VAR (PI - 4 bytes) detected at ast.c line 108 */
#line 356 "regression-bugs-tmp/cordic32.imp"
PHEX(_imp_INT(((((double)((double)((float)(THETA)) / (double)(((((float)(2)) * (PI))))))) * (65536))));
                                                                //    357        print string("; Sin(Theta) = "); write(CheckSinTheta, 0)    
#line 357 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; Sin(Theta) = "));
#line 357 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(CHECKSINTHETA, 0);
                                                                //    358        print string("; Cos(Theta) = "); write(CheckCosTheta, 0)
#line 358 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("; Cos(Theta) = "));
#line 358 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(CHECKCOSTHETA, 0);
                                                                //    359        newlines(2)
#line 359 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINES(2);
                                                                //    360    
                                                                //    361        err = CheckSinTheta - sinTheta; err = -err %if err < 0; sinErr = sinErr + err
#line 361 "regression-bugs-tmp/cordic32.imp"
ERR = (((int)(CHECKSINTHETA)) - (SINTHETA));
#line 361 "regression-bugs-tmp/cordic32.imp"
if (((ERR) >= (0))) goto L_0054;
#line 361 "regression-bugs-tmp/cordic32.imp"
ERR = (-(ERR));
#line 361 "regression-bugs-tmp/cordic32.imp"
L_0054:;
#line 361 "regression-bugs-tmp/cordic32.imp"
SINERR = (((int)(SINERR)) + (ERR));
                                                                //    362        err = CheckCosTheta - cosTheta; err = -err %if err < 0; cosErr = cosErr + err
#line 362 "regression-bugs-tmp/cordic32.imp"
ERR = (((int)(CHECKCOSTHETA)) - (COSTHETA));
#line 362 "regression-bugs-tmp/cordic32.imp"
if (((ERR) >= (0))) goto L_0055;
#line 362 "regression-bugs-tmp/cordic32.imp"
ERR = (-(ERR));
#line 362 "regression-bugs-tmp/cordic32.imp"
L_0055:;
#line 362 "regression-bugs-tmp/cordic32.imp"
COSERR = (((int)(COSERR)) + (ERR));
                                                                //    363    
                                                                //    364      %repeat
#line 364 "regression-bugs-tmp/cordic32.imp"
goto L_0051;
#line 364 "regression-bugs-tmp/cordic32.imp"
L_0052:;
                                                                //    365    
                                                                //    366      { Use this to test if algorithmic tweaks improve the accuracy }
                                                                //    367      print string("Cumulative error:  sin = "); write(sinErr, 0)
#line 367 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal("Cumulative error:  sin = "));
#line 367 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(SINERR, 0);
                                                                //    368      print string(",  cos = "); write(cosErr, 0)
#line 368 "regression-bugs-tmp/cordic32.imp"
_imp_PRINTSTRING(_imp_str_literal(",  cos = "));
#line 368 "regression-bugs-tmp/cordic32.imp"
_imp_WRITE(COSERR, 0);
                                                                //    369      newline
#line 369 "regression-bugs-tmp/cordic32.imp"
_imp_NEWLINE();
                                                                //    370      
                                                                //    371    %finish
#line 371 "regression-bugs-tmp/cordic32.imp"
L_0050:;
                                                                //    372  %end %of %program
#line 372 "regression-bugs-tmp/cordic32.imp"
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
#line 372 "regression-bugs-tmp/cordic32.imp"
// End of file
