void IIRFilter::setOrder(int n) { order = abs(n); if ((filterType == BP) && odd(order)) order++; ready = false; }
void mainbody( void ) { initialize () ; if ( ! organize () ) uexit ( 1 ) ; dosimplethings () ; if ( nl > 0 ) { {register integer for_end; ai = 0 ;for_end = nl - 1 ; if ( ai <= for_end) do activity [ai ]= 0 ; while ( ai++ < for_end ) ;} if ( tfm [4 * ( ligkernbase + ( 0 ) ) ]== 255 ) { left () ; Fputs ( plfile , "BOUNDARYCHAR" ) ; boundarychar = tfm [4 * ( ligkernbase + ( 0 ) ) + 1 ]; outchar ( boundarychar ) ; right () ; activity [0 ]= 1 ; } if ( tfm [4 * ( ligkernbase + ( nl - 1 ) ) ]== 255 ) { r = 256 * tfm [4 * ( ligkernbase + ( nl - 1 ) ) + 2 ]+ tfm [4 * ( ligkernbase + ( nl - 1 ) ) + 3 ]; if ( r >= nl ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } Fputs ( stderr , "Ligature/kern starting index for boundarychar is too large;" ) ; fprintf ( stderr , "%s\n", "so I removed it." ) ; } else { labelptr = 1 ; labeltable [1 ].cc = 256 ; labeltable [1 ].rr = r ; bcharlabel = r ; activity [r ]= 2 ; } activity [nl - 1 ]= 1 ; } } {register integer for_end; c = bc ;for_end = ec ; if ( c <= for_end) do if ( ( tfm [4 * ( charbase + c ) + 2 ]% 4 ) == 1 ) { r = tfm [4 * ( charbase + c ) + 3 ]; if ( r < nl ) { if ( tfm [4 * ( ligkernbase + ( r ) ) ]> 128 ) { r = 256 * tfm [4 * ( ligkernbase + ( r ) ) + 2 ]+ tfm [4 * ( ligkernbase + ( r ) ) + 3 ]; if ( r < nl ) { if ( activity [tfm [4 * ( charbase + c ) + 3 ]]== 0 ) activity [tfm [4 * ( charbase + c ) + 3 ]]= 1 ; } } } if ( r >= nl ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } Fputs ( stderr , "Ligature/kern starting index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I removed it." ) ; tfm [4 * ( charbase + c ) + 2 ]= 4 * ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) + 0 ; } else { sortptr = labelptr ; while ( labeltable [sortptr ].rr > r ) { labeltable [sortptr + 1 ]= labeltable [sortptr ]; sortptr = sortptr - 1 ; } labeltable [sortptr + 1 ].cc = c ; labeltable [sortptr + 1 ].rr = r ; labelptr = labelptr + 1 ; activity [r ]= 2 ; } } while ( c++ < for_end ) ;} labeltable [labelptr + 1 ].rr = ligsize ; if ( nl > 0 ) { left () ; Fputs ( plfile , "LIGTABLE" ) ; outln () ; {register integer for_end; ai = 0 ;for_end = nl - 1 ; if ( ai <= for_end) do if ( activity [ai ]== 2 ) { r = tfm [4 * ( ligkernbase + ( ai ) ) ]; if ( r < 128 ) { r = r + ai + 1 ; if ( r >= nl ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%ld%s\n", "Bad TFM file: " , "Ligature/kern step " , (long)ai , " skips too far;" ) ; } fprintf ( stderr , "%s\n", "I made it stop." ) ; tfm [4 * ( ligkernbase + ( ai ) ) ]= 128 ; } else activity [r ]= 2 ; } } while ( ai++ < for_end ) ;} sortptr = 1 ; {register integer for_end; acti = 0 ;for_end = nl - 1 ; if ( acti <= for_end) do if ( activity [acti ]!= 1 ) { i = acti ; if ( activity [i ]== 0 ) { if ( level == 1 ) { left () ; Fputs ( plfile , "COMMENT THIS PART OF THE PROGRAM IS NEVER USED!" ) ; outln () ; } } else if ( level == 2 ) right () ; while ( i == labeltable [sortptr ].rr ) { left () ; Fputs ( plfile , "LABEL" ) ; if ( labeltable [sortptr ].cc == 256 ) Fputs ( plfile , " BOUNDARYCHAR" ) ; else outchar ( labeltable [sortptr ].cc ) ; right () ; sortptr = sortptr + 1 ; } { k = 4 * ( ligkernbase + ( i ) ) ; if ( tfm [k ]> 128 ) { if ( 256 * tfm [k + 2 ]+ tfm [k + 3 ]>= nl ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s\n", "Bad TFM file: " , "Ligature unconditional stop command address is too big." ) ; } } else if ( tfm [k + 2 ]>= 128 ) { if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [ 4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) { if ( tfm [k + 1 ]!= boundarychar ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Kern step for" , " nonexistent character " ) ; printoctal ( tfm [k + 1 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 1 ]= bc ; } } left () ; Fputs ( plfile , "KRN" ) ; outchar ( tfm [k + 1 ]) ; r = 256 * ( tfm [k + 2 ]- 128 ) + tfm [k + 3 ]; if ( r >= nk ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s\n", "Bad TFM file: " , "Kern index too large." ) ; } Fputs ( plfile , " R 0.0" ) ; } else outfix ( 4 * ( kernbase + r ) ) ; right () ; } else { if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [ 4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) { if ( tfm [k + 1 ]!= boundarychar ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Ligature step for" , " nonexistent character " ) ; printoctal ( tfm [k + 1 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 1 ]= bc ; } } if ( ( ( tfm [k + 3 ]< bc ) || ( tfm [k + 3 ]> ec ) || ( tfm [ 4 * ( charbase + tfm [k + 3 ]) ]== 0 ) ) ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Ligature step produces the" , " nonexistent character " ) ; printoctal ( tfm [k + 3 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 3 ]= bc ; } left () ; r = tfm [k + 2 ]; if ( ( r == 4 ) || ( ( r > 7 ) && ( r != 11 ) ) ) { fprintf ( stderr , "%s\n", "Ligature step with nonstandard code changed to LIG" ) ; r = 0 ; tfm [k + 2 ]= 0 ; } if ( r % 4 > 1 ) putc ( '/' , plfile ); Fputs ( plfile , "LIG" ) ; if ( odd ( r ) ) putc ( '/' , plfile ); while ( r > 3 ) { putc ( '>' , plfile ); r = r - 4 ; } outchar ( tfm [k + 1 ]) ; outchar ( tfm [k + 3 ]) ; right () ; } if ( tfm [k ]> 0 ) { if ( level == 1 ) { if ( tfm [k ]>= 128 ) Fputs ( plfile , "(STOP)" ) ; else { count = 0 ; {register integer for_end; ai = i + 1 ;for_end = i + tfm [k ]; if ( ai <= for_end) do if ( activity [ai ]== 2 ) count = count + 1 ; while ( ai++ < for_end ) ;} fprintf ( plfile , "%s%ld%c", "(SKIP D " , (long)count , ')' ) ; } outln () ; } } } } while ( acti++ < for_end ) ;} if ( level == 2 ) right () ; right () ; hashptr = 0 ; yligcycle = 256 ; {register integer for_end; hh = 0 ;for_end = hashsize ; if ( hh <= for_end) do hash [hh ]= 0 ; while ( hh++ < for_end ) ;} {register integer for_end; c = bc ;for_end = ec ; if ( c <= for_end) do if ( ( tfm [4 * ( charbase + c ) + 2 ]% 4 ) == 1 ) { i = tfm [4 * ( charbase + c ) + 3 ]; if ( tfm [4 * ( ligkernbase + ( i ) ) ]> 128 ) i = 256 * tfm [4 * ( ligkernbase + ( i ) ) + 2 ]+ tfm [4 * ( ligkernbase + ( i ) ) + 3 ]; do { hashinput () ; k = tfm [4 * ( ligkernbase + ( i ) ) ]; if ( k >= 128 ) i = nl ; else i = i + 1 + k ; } while ( ! ( i >= nl ) ) ; } while ( c++ < for_end ) ;} if ( bcharlabel < nl ) { c = 256 ; i = bcharlabel ; do { hashinput () ; k = tfm [4 * ( ligkernbase + ( i ) ) ]; if ( k >= 128 ) i = nl ; else i = i + 1 + k ; } while ( ! ( i >= nl ) ) ; } if ( hashptr == hashsize ) { fprintf ( stderr , "%s\n", "Sorry, I haven't room for so many ligature/kern pairs!" ) ; uexit ( 1 ) ; } {register integer for_end; hh = 1 ;for_end = hashptr ; if ( hh <= for_end) do { r = hashlist [hh ]; if ( classvar [r ]> 0 ) r = ffn ( r , ( hash [r ]- 1 ) / 256 , ( hash [r ]- 1 ) % 256 ) ; } while ( hh++ < for_end ) ;} if ( yligcycle < 256 ) { Fputs ( stderr , "Infinite ligature loop starting with " ) ; if ( xligcycle == 256 ) Fputs ( stderr , "boundary" ) ; else printoctal ( xligcycle ) ; Fputs ( stderr , " and " ) ; printoctal ( yligcycle ) ; { putc ( '!' , stderr ); putc ( '\n', stderr ); } Fputs ( plfile , "(INFINITE LIGATURE LOOP MUST BE BROKEN!)" ) ; uexit ( 1 ) ; } } if ( ne > 0 ) {register integer for_end; c = 0 ;for_end = ne - 1 ; if ( c <= for_end) do {register integer for_end; d = 0 ;for_end = 3 ; if ( d <= for_end) do { k = 4 * ( extenbase + c ) + d ; if ( ( tfm [k ]> 0 ) || ( d == 3 ) ) { if ( ( ( tfm [k ]< bc ) || ( tfm [k ]> ec ) || ( tfm [4 * ( charbase + tfm [k ]) ]== 0 ) ) ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Extensible recipe involves the" , " nonexistent character " ) ; printoctal ( tfm [k ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } } if ( d < 3 ) tfm [k ]= 0 ; } } } while ( d++ < for_end ) ;} while ( c++ < for_end ) ;} docharacters () ; if ( verbose ) { putc ( '.' , stderr ); putc ( '\n', stderr ); } if ( level != 0 ) fprintf ( stderr , "%s\n", "This program isn't working!" ) ; if ( ! perfect ) { Fputs ( plfile , "(COMMENT THE TFM FILE WAS BAD, SO THE DATA HAS BEEN CHANGED!)" ) ; putc ('\n', plfile ); } }
template<typename T> inline constexpr bool even(const T a) { return !odd(a); }
static char * eps_to_pict(char *s) /****************************************************************************** purpose : create a pict file from an EPS file and return file name for the pict file. Ideally this file will contain both the bitmap and the original EPS embedded in the PICT file as comments. If a bitmap cannot be created, then the EPS is still embedded in the PICT file so that at least the printed version will be good. ******************************************************************************/ { char *cmd, *p, buffer[560]; size_t cmd_len; long ii, pict_bitmap_size, eps_size; short err,handle_size; unsigned char byte; short PostScriptBegin = 190; short PostScriptEnd = 191; short PostScriptHandle = 192; char *pict_bitmap =NULL; char *pict_eps =NULL; char *eps =NULL; char *return_value =NULL; FILE *fp_eps =NULL; FILE *fp_pict_bitmap =NULL; FILE *fp_pict_eps =NULL; diagnostics(2, "eps_to_pict filename = <%s>", s); /* Create filename for bitmap */ p = strdup_new_extension(s, ".eps", "a.pict"); if (p == NULL) { p = strdup_new_extension(s, ".EPS", "a.pict"); if (p == NULL) goto Exit; } pict_bitmap = strdup_tmp_path(p); free(p); /* Create filename for eps file */ p = strdup_new_extension(s, ".eps", ".pict"); if (p == NULL) { p = strdup_new_extension(s, ".EPS", ".pict"); if (p == NULL) goto Exit; } pict_eps = strdup_tmp_path(p); free(p); eps = strdup_together(g_home_dir,s); /* create a bitmap version of the eps file */ cmd_len = strlen(eps)+strlen(pict_bitmap)+strlen("convert -crop 0x0 -density ")+40; cmd = (char *) malloc(cmd_len); snprintf(cmd, cmd_len, "convert -crop 0x0 -density %d %s %s", g_dots_per_inch, eps, pict_bitmap); diagnostics(2, "system graphics command = [%s]", cmd); err = system(cmd); free(cmd); if (err!=0) diagnostics(WARNING, "problem creating bitmap from %s", eps); else return_value = pict_bitmap; /* open the eps file and make sure that it is less than 32k */ fp_eps = fopen (eps, "rb"); if (fp_eps==NULL) goto Exit; fseek(fp_eps, 0, SEEK_END); eps_size = ftell (fp_eps); if (eps_size > 32000) { diagnostics(WARNING, "EPS file >32K ... using bitmap only"); goto Exit; } rewind (fp_eps); diagnostics(WARNING, "eps size is 0x%X bytes", eps_size); /*open bitmap pict file and get file size */ fp_pict_bitmap = fopen(pict_bitmap, "rb"); if (fp_pict_bitmap == NULL) goto Exit; fseek(fp_pict_bitmap, 0, SEEK_END); pict_bitmap_size = ftell(fp_pict_bitmap); rewind(fp_pict_bitmap); /*open new pict file */ fp_pict_eps = fopen(pict_eps, "w"); if (fp_pict_eps == NULL) goto Exit; /*copy header 512 buffer + 40 byte header*/ if (fread( &buffer,1,512+40,fp_pict_bitmap)!=512+40) goto Exit; if (fwrite(&buffer,1,512+40,fp_pict_eps)!=512+40) goto Exit; /* insert comment that allows embedding postscript */ PicComment(PostScriptBegin,0,fp_pict_eps); /*copy bitmap 512+40 bytes of header + 2 bytes at end */ for (ii=512+40+2; ii<pict_bitmap_size; ii++) { if(fread (&byte,1,1,fp_pict_bitmap)!=1) goto Exit; if(fwrite(&byte,1,1,fp_pict_eps )!=1) goto Exit; } /*copy eps graphic (write an even number of bytes) */ handle_size = eps_size; if (odd(eps_size)) handle_size ++; PicComment(PostScriptHandle,handle_size,fp_pict_eps); for (ii=0; ii<eps_size; ii++) { if(fread(&byte,1,1,fp_eps)!=1) goto Exit; if(fwrite(&byte,1,1,fp_pict_eps)!=1) goto Exit; } if (odd(eps_size)) { byte = ' '; if(fwrite(&byte,1,1,fp_pict_eps) !=1) goto Exit; } /*close file*/ PicComment(PostScriptEnd,0,fp_pict_eps); byte = 0x00; if (fwrite(&byte,1,1,fp_pict_eps)!=1) goto Exit; byte = 0xFF; if (fwrite(&byte,1,1,fp_pict_eps)!=1) goto Exit; return_value= pict_eps; Exit: if (eps) free(eps); if (pict_eps) free(pict_eps); if (pict_bitmap) free(pict_bitmap); if (fp_eps) fclose(fp_eps); if (fp_pict_eps) fclose(fp_pict_eps); if (fp_pict_bitmap) fclose(fp_pict_bitmap); return return_value; }
void SixJSymbol (double l2, double l3, double l4, double l5, double l6, double &l1min, double &l1max, double *sixcof, int ndim, int &errflag) { const double zero = 0.0, eps = 0.01, one = 1.0, two = 2.0, three = 3.0; int nfin, nlim, i, n, index, lstep, nfinp1, nfinp2, nfinp3, nstep2; double c1old = 0.0, sign1, sign2, x, y, denom = 0.0, cnorm, ratio, a1, a2, c1, c2, l1, x1, x2, x3, y1, y2, y3, oldfac, dv, newfac, sumbac = 0.0, thresh, a1s, a2s, sumfor, sumuni, sum1, sum2; // Parameter adjustments --sixcof; errflag = 0; // "hugedouble" is the square root of one twentieth of the largest floating // point number, approximately. double hugedouble = sqrt(DBL_MAX / 20.0), srhuge = sqrt(hugedouble), tiny = one / hugedouble, srtiny = one / srhuge; // lmatch = zero // Check error conditions 1, 2, and 3. if (fmod(l2+l3+l5+l6+eps,one) >= eps + eps || fmod(l4+l2+l6+eps, one) >= eps + eps) { errflag = 1; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "l2+l3+l5+l6 or l4+l2+l6 not integer."); return; } else if (l4+l2-l6 < zero || l4-l2+l6 < zero || -l4+l2+l6 < zero) { errflag = 2; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "L4, L2, L6 triangular condition not satisfied."); return; } else if (l4-l5+l3 < zero || l4+l5-l3 < zero || -l4+l5+l3 < zero) { errflag = 3; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "L4, L5, L3 triangular condition not satisfied."); return; } // Limits for l1 l1min = MpMax(fabs(l2-l3),fabs(l5-l6)); l1max = MpMin(l2+l3,l5+l6); // Check error condition 4. if (fmod(l1max-l1min+eps,one) >= eps + eps) { errflag = 4; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "l1max-l1min not integer."); return; } if (l1min < l1max - eps) goto L20; if (l1min < l1max + eps) goto L10; // Check error condition 5. errflag = 5; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "l1min greater than l1max."); return; // This is reached in case that l1 can take only one value L10: // lscale = 0 sixcof[1] = (odd(int(l2+l3+l5+l6+eps)) ? -one : one) / sqrt((l1min+l1min+one)*(l4+l4+one)); return; // This is reached in case that l1 can take more than one value. L20: // lscale = 0 nfin = int(l1max-l1min+one+eps); if (ndim - nfin >= 0) goto L23; // Check error condition 6. errflag = 6; Matpack.Error(Mat::ArgumentDomain, "%s: %s", "SixJSymbol", "Dimension of result array for 6j coefficients too small."); return; // Start of forward recursion L23: l1 = l1min; newfac = 0.0; c1 = 0.0; sixcof[1] = srtiny; sum1 = (l1 + l1 + one) * tiny; lstep = 1; L30: ++lstep; l1 += one; oldfac = newfac; a1 = (l1+l2+l3+one) * (l1-l2+l3) * (l1+l2-l3) * (-l1+l2+l3+one); a2 = (l1+l5+l6+one) * (l1-l5+l6) * (l1+l5-l6) * (-l1+l5+l6+one); newfac = sqrt(a1 * a2); if (l1 < one + eps) goto L40; dv = two * (l2 * (l2+one) * l5 * (l5+one) + l3 * (l3+one) * l6 * (l6+one) - l1 * (l1-one) * l4 * (l4+one)) - (l2 * (l2+one) + l3 * (l3+one) - l1 * (l1-one)) * (l5 * (l5+one) + l6 * (l6+one) - l1 * (l1-one)); denom = (l1-one) * newfac; if (lstep - 2 <= 0) goto L32; c1old = fabs(c1); L32: c1 = -(l1+l1-one) * dv / denom; goto L50; // if l1 = 1, (l1 - 1) has to be factored out of dv, hence L40: c1 = -two * (l2 * (l2+one) + l5 * (l5+one) - l4 * (l4+one)) / newfac; L50: if (lstep > 2) goto L60; // If l1 = l1min + 1, the third term in recursion equation vanishes x = srtiny * c1; sixcof[2] = x; sum1 += tiny * (l1+l1+one) * c1 * c1; if (lstep == nfin) goto L220; goto L30; L60: c2 = -l1 * oldfac / denom; // Recursion to the next 6j coefficient x x = c1 * sixcof[lstep-1] + c2 * sixcof[lstep-2]; sixcof[lstep] = x; sumfor = sum1; sum1 += (l1+l1+one) * x * x; if (lstep == nfin) goto L100; // See if last unnormalized 6j coefficient exceeds srhuge if (fabs(x) < srhuge) goto L80; // This is reached if last 6j coefficient larger than srhuge, // so that the recursion series sixcof(1), ... ,sixcof(lstep) // has to be rescaled to prevent overflow // lscale = lscale + 1 for (i = 1; i <= lstep; ++i) { if (fabs(sixcof[i]) < srtiny) sixcof[i] = zero; sixcof[i] /= srhuge; } sum1 /= hugedouble; sumfor /= hugedouble; x /= srhuge; // As long as the coefficient abs(c1) is decreasing, the recursion // proceeds towards increasing 6j values and, hence, is numerically // stable. Once an increase of abs(c1) is detected, the recursion // direction is reversed. L80: if (c1old - fabs(c1) <= 0.0) goto L100; else goto L30; // Keep three 6j coefficients around lmatch for comparison later // with backward recursion. L100: // lmatch = l1 - 1 x1 = x; x2 = sixcof[lstep-1]; x3 = sixcof[lstep-2]; // Starting backward recursion from l1max taking nstep2 steps, so // that forward and backward recursion overlap at the three points // l1 = lmatch+1, lmatch, lmatch-1. nfinp1 = nfin + 1; nfinp2 = nfin + 2; nfinp3 = nfin + 3; nstep2 = nfin - lstep + 3; l1 = l1max; sixcof[nfin] = srtiny; sum2 = (l1 + l1 + one) * tiny; l1 += two; lstep = 1; L110: ++lstep; l1 -= one; oldfac = newfac; a1s = (l1+l2+l3) * (l1-l2+l3-one) * (l1+l2-l3-one) * (-l1+l2+l3+two); a2s = (l1+l5+l6) * (l1-l5+l6-one) * (l1+l5-l6-one) * (-l1+l5+l6+two); newfac = sqrt(a1s * a2s); dv = two * (l2 * (l2+one) * l5 * (l5+one) + l3 * (l3+one) * l6 * (l6+one) - l1 * (l1-one) * l4 * (l4+one)) - (l2 * (l2+one) + l3 * (l3+one) - l1 * (l1-one)) * (l5 * (l5+one) + l6 * (l6+one) - l1 * (l1-one)); denom = l1 * newfac; c1 = -(l1+l1-one) * dv / denom; if (lstep > 2) goto L120; // If l1 = l1max + 1 the third term in the recursion equation vanishes y = srtiny * c1; sixcof[nfin - 1] = y; if (lstep == nstep2) goto L200; sumbac = sum2; sum2 += (l1+l1-three) * c1 * c1 * tiny; goto L110; L120: c2 = -(l1-one) * oldfac / denom; // Recursion to the next 6j coefficient y y = c1 * sixcof[nfinp2 - lstep] + c2 * sixcof[nfinp3 - lstep]; if (lstep == nstep2) goto L200; sixcof[nfinp1 - lstep] = y; sumbac = sum2; sum2 += (l1+l1-three) * y * y; // See if last unnormalized 6j coefficient exceeds srhuge if (fabs(y) < srhuge) goto L110; // This is reached if last 6j coefficient larger than srhuge, // so that the recursion series sixcof(nfin), ... ,sixcof(nfin-lstep+1) // has to be rescaled to prevent overflow // lscale = lscale + 1 for (i = 1; i <= lstep; ++i) { index = nfin - i + 1; if (fabs(sixcof[index]) < srtiny) sixcof[index] = zero; sixcof[index] /= srhuge; } sumbac /= hugedouble; sum2 /= hugedouble; goto L110; // The forward recursion 6j coefficients x1, x2, x3 are to be matched // with the corresponding backward recursion values y1, y2, y3. L200: y3 = y; y2 = sixcof[nfinp2 - lstep]; y1 = sixcof[nfinp3 - lstep]; // Determine now ratio such that yi = ratio * xi (i=1,2,3) holds // with minimal error. ratio = (x1*y1 + x2*y2 + x3*y3) / (x1*x1 + x2*x2 + x3*x3); nlim = nfin - nstep2 + 1; if (fabs(ratio) < one) goto L211; for (n = 1; n <= nlim; ++n) sixcof[n] = ratio * sixcof[n]; sumuni = ratio * ratio * sumfor + sumbac; goto L230; L211: ++nlim; ratio = one / ratio; for (n = nlim; n <= nfin; ++n) sixcof[n] = ratio * sixcof[n]; sumuni = sumfor + ratio * ratio * sumbac; goto L230; L220: sumuni = sum1; // Normalize 6j coefficients L230: cnorm = one / sqrt((l4+l4+one) * sumuni); // Sign convention for last 6j coefficient determines overall phase sign1 = CopySign(one,sixcof[nfin]); sign2 = odd(int(l2+l3+l5+l6+eps)) ? -one : one; if (sign1 * sign2 <= 0.0) goto L235; else goto L236; L235: cnorm = -cnorm; L236: if (fabs(cnorm) < one) goto L250; for (n = 1; n <= nfin; ++n) sixcof[n] = cnorm * sixcof[n]; return; L250: thresh = tiny / fabs(cnorm); for (n = 1; n <= nfin; ++n) { if (fabs(sixcof[n]) < thresh) sixcof[n] = zero; sixcof[n] = cnorm * sixcof[n]; } }
/* * Translate the rowinfo to a member of the row_info enumeration */ row_info_enum eGet6RowInfo(int iFodo, const UCHAR *aucGrpprl, int iBytes, row_block_type *pRow) { int iFodoOff, iInfoLen; int iIndex, iSize, iCol; int iPosCurr, iPosPrev; USHORT usTmp; BOOL bFound24_0, bFound24_1, bFound25_0, bFound25_1, bFound190; fail(iFodo < 0 || aucGrpprl == NULL || pRow == NULL); iFodoOff = 0; bFound24_0 = FALSE; bFound24_1 = FALSE; bFound25_0 = FALSE; bFound25_1 = FALSE; bFound190 = FALSE; while (iBytes >= iFodoOff + 1) { iInfoLen = 0; switch (ucGetByte(iFodo + iFodoOff, aucGrpprl)) { case 24: /* fInTable */ if (odd(ucGetByte(iFodo + iFodoOff + 1, aucGrpprl))) { bFound24_1 = TRUE; } else { bFound24_0 = TRUE; } break; case 25: /* fTtp */ if (odd(ucGetByte(iFodo + iFodoOff + 1, aucGrpprl))) { bFound25_1 = TRUE; } else { bFound25_0 = TRUE; } break; case 38: /* brcTop */ usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl); usTmp &= 0x0018; NO_DBG_DEC(usTmp >> 3); if (usTmp == 0) { pRow->ucBorderInfo &= ~TABLE_BORDER_TOP; } else { pRow->ucBorderInfo |= TABLE_BORDER_TOP; } break; case 39: /* brcLeft */ usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl); usTmp &= 0x0018; NO_DBG_DEC(usTmp >> 3); if (usTmp == 0) { pRow->ucBorderInfo &= ~TABLE_BORDER_LEFT; } else { pRow->ucBorderInfo |= TABLE_BORDER_LEFT; } break; case 40: /* brcBottom */ usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl); usTmp &= 0x0018; NO_DBG_DEC(usTmp >> 3); if (usTmp == 0) { pRow->ucBorderInfo &= ~TABLE_BORDER_BOTTOM; } else { pRow->ucBorderInfo |= TABLE_BORDER_BOTTOM; } break; case 41: /* brcRight */ usTmp = usGetWord(iFodo + iFodoOff + 1, aucGrpprl); usTmp &= 0x0018; NO_DBG_DEC(usTmp >> 3); if (usTmp == 0) { pRow->ucBorderInfo &= ~TABLE_BORDER_RIGHT; } else { pRow->ucBorderInfo |= TABLE_BORDER_RIGHT; } break; case 188: /* cDefTable10 */ DBG_MSG("188: sprmTDefTable10"); iSize = (int)usGetWord(iFodo + iFodoOff + 1, aucGrpprl); DBG_DEC(iSize); break; case 190: /* cDefTable */ iSize = (int)usGetWord(iFodo + iFodoOff + 1, aucGrpprl); if (iSize < 6 || iBytes < iFodoOff + 7) { DBG_DEC(iSize); DBG_DEC(iFodoOff); iInfoLen = 1; break; } iCol = (int)ucGetByte(iFodo + iFodoOff + 3, aucGrpprl); if (iCol < 1 || iBytes < iFodoOff + 3 + (iCol + 1) * 2) { DBG_DEC(iCol); DBG_DEC(iFodoOff); iInfoLen = 1; break; } if (iCol >= (int)elementsof(pRow->asColumnWidth)) { DBG_DEC(iCol); werr(1, "The number of columns is corrupt"); } pRow->ucNumberOfColumns = (UCHAR)iCol; iPosPrev = (int)(short)usGetWord( iFodo + iFodoOff + 4, aucGrpprl); for (iIndex = 0; iIndex < iCol; iIndex++) { iPosCurr = (int)(short)usGetWord( iFodo + iFodoOff + 6 + iIndex * 2, aucGrpprl); pRow->asColumnWidth[iIndex] = (short)(iPosCurr - iPosPrev); iPosPrev = iPosCurr; } bFound190 = TRUE; break; default: break; } if (iInfoLen <= 0) { iInfoLen = iGet6InfoLength(iFodo + iFodoOff, aucGrpprl); fail(iInfoLen <= 0); } iFodoOff += iInfoLen; } if (bFound25_1 && bFound190) { return found_end_of_row; } if (bFound25_0 && !bFound190) { return found_not_end_of_row; } if (bFound24_1) { return found_a_cell; } if (bFound24_0) { return found_not_a_cell; } return found_nothing; } /* end of eGet6RowInfo */
int main(void) { printf("%ld\n", odd(1, 2)); return 0; }
int GreaterOdd(int i) { return odd(i) ? i + 2 : i + 1; }
int EmbeddingDirection(int level) { return odd(level) ? R : L; }
/************************************************************* * BIDI_Reorder * * Returns TRUE if reordering was required and done. */ BOOL BIDI_Reorder( HDC hDC, /*[in] Display DC */ LPCWSTR lpString, /* [in] The string for which information is to be returned */ INT uCount, /* [in] Number of WCHARs in string. */ DWORD dwFlags, /* [in] GetCharacterPlacement compatible flags specifying how to process the string */ DWORD dwWineGCP_Flags, /* [in] Wine internal flags - Force paragraph direction */ LPWSTR lpOutString, /* [out] Reordered string */ INT uCountOut, /* [in] Size of output buffer */ UINT *lpOrder, /* [out] Logical -> Visual order map */ WORD **lpGlyphs, /* [out] reordered, mirrored, shaped glyphs to display */ INT *cGlyphs /* [out] number of glyphs generated */ ) { WORD *chartype; BYTE *levels; INT i, done; unsigned glyph_i; BOOL is_complex; int maxItems; int nItems; SCRIPT_CONTROL Control; SCRIPT_STATE State; SCRIPT_ITEM *pItems; HRESULT res; SCRIPT_CACHE psc = NULL; WORD *run_glyphs = NULL; WORD *pwLogClust = NULL; SCRIPT_VISATTR *psva = NULL; DWORD cMaxGlyphs = 0; BOOL doGlyphs = TRUE; TRACE("%s, %d, 0x%08x lpOutString=%p, lpOrder=%p\n", debugstr_wn(lpString, uCount), uCount, dwFlags, lpOutString, lpOrder); memset(&Control, 0, sizeof(Control)); memset(&State, 0, sizeof(State)); if (lpGlyphs) *lpGlyphs = NULL; if (!(dwFlags & GCP_REORDER)) { FIXME("Asked to reorder without reorder flag set\n"); return FALSE; } if (lpOutString && uCountOut < uCount) { FIXME("lpOutString too small\n"); return FALSE; } chartype = HeapAlloc(GetProcessHeap(), 0, uCount * sizeof(WORD)); if (!chartype) { WARN("Out of memory\n"); return FALSE; } if (lpOutString) memcpy(lpOutString, lpString, uCount * sizeof(WCHAR)); is_complex = FALSE; for (i = 0; i < uCount && !is_complex; i++) { if ((lpString[i] >= 0x900 && lpString[i] <= 0xfff) || (lpString[i] >= 0x1cd0 && lpString[i] <= 0x1cff) || (lpString[i] >= 0xa840 && lpString[i] <= 0xa8ff)) is_complex = TRUE; } /* Verify reordering will be required */ if ((WINE_GCPW_FORCE_RTL == (dwWineGCP_Flags&WINE_GCPW_DIR_MASK)) || ((dwWineGCP_Flags&WINE_GCPW_DIR_MASK) == WINE_GCPW_LOOSE_RTL)) State.uBidiLevel = 1; else if (!is_complex) { done = 1; classify(lpString, chartype, uCount); for (i = 0; i < uCount; i++) switch (chartype[i]) { case R: case AL: case RLE: case RLO: done = 0; break; } if (done) { HeapFree(GetProcessHeap(), 0, chartype); if (lpOrder) { for (i = 0; i < uCount; i++) lpOrder[i] = i; } return TRUE; } } levels = HeapAlloc(GetProcessHeap(), 0, uCount * sizeof(BYTE)); if (!levels) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); return FALSE; } maxItems = 5; pItems = HeapAlloc(GetProcessHeap(),0, maxItems * sizeof(SCRIPT_ITEM)); if (!pItems) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); return FALSE; } if (lpGlyphs) { #ifdef __REACTOS__ /* ReactOS r57677 and r57679 */ cMaxGlyphs = 3 * uCount / 2 + 16; #else cMaxGlyphs = 1.5 * uCount + 16; #endif run_glyphs = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * cMaxGlyphs); if (!run_glyphs) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); return FALSE; } pwLogClust = HeapAlloc(GetProcessHeap(),0,sizeof(WORD) * uCount); if (!pwLogClust) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); HeapFree(GetProcessHeap(), 0, run_glyphs); return FALSE; } psva = HeapAlloc(GetProcessHeap(),0,sizeof(SCRIPT_VISATTR) * uCount); if (!psva) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); HeapFree(GetProcessHeap(), 0, run_glyphs); HeapFree(GetProcessHeap(), 0, pwLogClust); return FALSE; } } done = 0; glyph_i = 0; while (done < uCount) { INT j; classify(lpString + done, chartype, uCount - done); /* limit text to first block */ i = resolveParagraphs(chartype, uCount - done); for (j = 0; j < i; ++j) switch(chartype[j]) { case B: case S: case WS: case ON: chartype[j] = N; default: continue; } if ((dwWineGCP_Flags&WINE_GCPW_DIR_MASK) == WINE_GCPW_LOOSE_RTL) State.uBidiLevel = 1; else if ((dwWineGCP_Flags&WINE_GCPW_DIR_MASK) == WINE_GCPW_LOOSE_LTR) State.uBidiLevel = 0; if (dwWineGCP_Flags & WINE_GCPW_LOOSE_MASK) { for (j = 0; j < i; ++j) if (chartype[j] == L) { State.uBidiLevel = 0; break; } else if (chartype[j] == R || chartype[j] == AL) { State.uBidiLevel = 1; break; } } res = ScriptItemize(lpString + done, i, maxItems, &Control, &State, pItems, &nItems); while (res == E_OUTOFMEMORY) { maxItems = maxItems * 2; pItems = HeapReAlloc(GetProcessHeap(), 0, pItems, sizeof(SCRIPT_ITEM) * maxItems); if (!pItems) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, run_glyphs); HeapFree(GetProcessHeap(), 0, pwLogClust); HeapFree(GetProcessHeap(), 0, psva); return FALSE; } res = ScriptItemize(lpString + done, i, maxItems, &Control, &State, pItems, &nItems); } if (lpOutString || lpOrder) for (j = 0; j < nItems; j++) { int k; for (k = pItems[j].iCharPos; k < pItems[j+1].iCharPos; k++) levels[k] = pItems[j].a.s.uBidiLevel; } if (lpOutString) { /* assign directional types again, but for WS, S this time */ classify(lpString + done, chartype, i); BidiLines(State.uBidiLevel, lpOutString + done, lpString + done, chartype, levels, i, 0); } if (lpOrder) { int k, lastgood; for (j = lastgood = 0; j < i; ++j) if (levels[j] != levels[lastgood]) { --j; if (odd(levels[lastgood])) for (k = j; k >= lastgood; --k) lpOrder[done + k] = done + j - k; else for (k = lastgood; k <= j; ++k) lpOrder[done + k] = done + k; lastgood = ++j; } if (odd(levels[lastgood])) for (k = j - 1; k >= lastgood; --k) lpOrder[done + k] = done + j - 1 - k; else for (k = lastgood; k < j; ++k) lpOrder[done + k] = done + k; } if (lpGlyphs && doGlyphs) { BYTE *runOrder; int *visOrder; SCRIPT_ITEM *curItem; runOrder = HeapAlloc(GetProcessHeap(), 0, maxItems * sizeof(*runOrder)); visOrder = HeapAlloc(GetProcessHeap(), 0, maxItems * sizeof(*visOrder)); if (!runOrder || !visOrder) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, runOrder); HeapFree(GetProcessHeap(), 0, visOrder); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); HeapFree(GetProcessHeap(), 0, psva); HeapFree(GetProcessHeap(), 0, pwLogClust); return FALSE; } for (j = 0; j < nItems; j++) runOrder[j] = pItems[j].a.s.uBidiLevel; ScriptLayout(nItems, runOrder, visOrder, NULL); for (j = 0; j < nItems; j++) { int k; int cChars,cOutGlyphs; curItem = &pItems[visOrder[j]]; cChars = pItems[visOrder[j]+1].iCharPos - curItem->iCharPos; res = ScriptShape(hDC, &psc, lpString + done + curItem->iCharPos, cChars, cMaxGlyphs, &curItem->a, run_glyphs, pwLogClust, psva, &cOutGlyphs); while (res == E_OUTOFMEMORY) { cMaxGlyphs *= 2; run_glyphs = HeapReAlloc(GetProcessHeap(), 0, run_glyphs, sizeof(WORD) * cMaxGlyphs); if (!run_glyphs) { WARN("Out of memory\n"); HeapFree(GetProcessHeap(), 0, runOrder); HeapFree(GetProcessHeap(), 0, visOrder); HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); HeapFree(GetProcessHeap(), 0, psva); HeapFree(GetProcessHeap(), 0, pwLogClust); HeapFree(GetProcessHeap(), 0, *lpGlyphs); ScriptFreeCache(&psc); *lpGlyphs = NULL; return FALSE; } res = ScriptShape(hDC, &psc, lpString + done + curItem->iCharPos, cChars, cMaxGlyphs, &curItem->a, run_glyphs, pwLogClust, psva, &cOutGlyphs); } if (res) { if (res == USP_E_SCRIPT_NOT_IN_FONT) TRACE("Unable to shape with currently selected font\n"); else FIXME("Unable to shape string (%x)\n",res); j = nItems; doGlyphs = FALSE; HeapFree(GetProcessHeap(), 0, *lpGlyphs); *lpGlyphs = NULL; } else { if (*lpGlyphs) *lpGlyphs = HeapReAlloc(GetProcessHeap(), 0, *lpGlyphs, sizeof(WORD) * (glyph_i + cOutGlyphs)); else *lpGlyphs = HeapAlloc(GetProcessHeap(), 0, sizeof(WORD) * (glyph_i + cOutGlyphs)); for (k = 0; k < cOutGlyphs; k++) (*lpGlyphs)[glyph_i+k] = run_glyphs[k]; glyph_i += cOutGlyphs; } } HeapFree(GetProcessHeap(), 0, runOrder); HeapFree(GetProcessHeap(), 0, visOrder); } done += i; } if (cGlyphs) *cGlyphs = glyph_i; HeapFree(GetProcessHeap(), 0, chartype); HeapFree(GetProcessHeap(), 0, levels); HeapFree(GetProcessHeap(), 0, pItems); HeapFree(GetProcessHeap(), 0, run_glyphs); HeapFree(GetProcessHeap(), 0, pwLogClust); HeapFree(GetProcessHeap(), 0, psva); ScriptFreeCache(&psc); return TRUE; }
int GreaterEven(int i) { return odd(i) ? i + 1 : i + 2; }
bool even (int i) { return !odd(i);}
void IIRFilter::locatePolesAndZeros(){ // determines poles and zeros of IIR filter // based on bilinear transform method pReal = new double[order + 1]; pImag = new double[order + 1]; z = new double[order + 1]; double ln10 = log(10.0); for(int k = 1; k <= order; k++) { pReal[k] = 0.0; pImag[k] = 0.0; } // Butterworth, Chebyshev parameters int n = order; if (filterType == BP) n = n/2; int ir = n % 2; int n1 = n + ir; int n2 = (3*n + ir)/2 - 1; double f1; switch (filterType) { case LP: f1 = fp2; break; case HP: f1 = fN - fp1; break; case BP: f1 = fp2 - fp1; break; default: f1 = 0.0; } double tanw1 = tan(0.5*M_PI*f1/fN); double tansqw1 = sqr(tanw1); // Real and Imaginary parts of low-pass poles double t, a = 1.0, r = 1.0, i = 1.0; double b3; for (int k = n1; k <= n2; k++) { t = 0.5*(2*k + 1 - ir)*M_PI/(double)n; switch (prototype) { case BUTTERWORTH: b3 = 1.0 - 2.0*tanw1*cos(t) + tansqw1; r = (1.0 - tansqw1)/b3; i = 2.0*tanw1*sin(t)/b3; break; case CHEBYSHEV: double d = 1.0 - exp(-0.05*ripple*ln10); double e = 1.0 / sqrt(1.0 / sqr(1.0 - d) - 1.0); double x = pow(sqrt(e*e + 1.0) + e, 1.0/(double)n); a = 0.5*(x - 1.0/x); double b = 0.5*(x + 1.0/x); double c3 = a*tanw1*cos(t); double c4 = b*tanw1*sin(t); double c5 = sqr(1.0 - c3) + sqr(c4); r = 2.0*(1.0 - c3)/c5 - 1.0; i = 2.0*c4/c5; break; } int m = 2*(n2 - k) + 1; pReal[m + ir] = r; pImag[m + ir] = std::abs(i); pReal[m + ir + 1] = r; pImag[m + ir + 1] = - std::abs(i); } if (odd(n)) { if (prototype == BUTTERWORTH) r = (1.0 - tansqw1)/(1.0 + 2.0*tanw1+tansqw1); if (prototype == CHEBYSHEV) r = 2.0/(1.0 + a*tanw1) - 1.0; pReal[1] = r; pImag[1] = 0.0; } double aa; double f4; double f5; switch (filterType) { case LP: for (int m = 1; m <= n; m++) z[m]= -1.0; break; case HP: // low-pass to high-pass transformation for (int m = 1; m <= n; m++) { pReal[m] = -pReal[m]; z[m] = 1.0; } break; case BP: // low-pass to bandpass transformation for (int m = 1; m <= n; m++) { z[m] = 1.0; z[m+n]= -1.0; } f4 = 0.5*M_PI*fp1/fN; f5 = 0.5*M_PI*fp2/fN; /* check this bit ... needs value for gp to adjust critical freqs if (prototype == BUTTERWORTH) { f4 = f4/Math.exp(0.5*Math.log(gp)/n); f5 = fN - (fN - f5)/Math.exp(0.5*Math.log(gp)/n); } */ aa = cos(f4 + f5)/cos(f5 - f4); double aR, aI, h1, h2, p1R, p2R, p1I, p2I; for (int m1 = 0; m1 <= (order - 1)/2; m1++) { int m = 1 + 2*m1; aR = pReal[m]; aI = pImag[m]; if (std::abs(aI) < 0.0001) { h1 = 0.5*aa*(1.0 + aR); h2 = sqr(h1) - aR; if (h2 > 0.0) { p1R = h1 + sqrt(h2); p2R = h1 - sqrt(h2); p1I = 0.0; p2I = 0.0; } else { p1R = h1; p2R = h1; p1I = sqrt(std::abs(h2)); p2I = -p1I; } } else { double fR = aa*0.5*(1.0 + aR); double fI = aa*0.5*aI; double gR = sqr(fR) - sqr(fI) - aR; double gI = 2*fR*fI - aI; double sR = sqrt(0.5*std::abs(gR + sqrt(sqr(gR) + sqr(gI)))); double sI = gI/(2.0*sR); p1R = fR + sR; p1I = fI + sI; p2R = fR - sR; p2I = fI - sI; } pReal[m] = p1R; pReal[m+1] = p2R; pImag[m] = p1I; pImag[m+1] = p2I; } // end of m1 for-loop if (odd(n)) { pReal[2] = pReal[n+1]; pImag[2] = pImag[n+1]; } for (int k = n; k >= 1; k--) { int m = 2*k - 1; pReal[m] = pReal[k]; pReal[m+1] = pReal[k]; pImag[m] = std::abs(pImag[k]); pImag[m+1] = - std::abs(pImag[k]); } break; default: break; } }
//todo: change to float from double to get same precision as York void IIRFilter::design() { //Working memory for filter() //Init here because order has been set xv1 = new float[order + 1]; yv1 = new float[order + 1]; xv2 = new float[order + 1]; yv2 = new float[order + 1]; aCoeff = new float[order + 1]; bCoeff = new float[order + 1]; float *newA = new float[order + 1]; float *newB = new float[order + 1]; locatePolesAndZeros(); // find filter poles and zeros // compute filter coefficients from pole/zero values for (int i = 0; i <= order; i++) { aCoeff[i] = 0.0; bCoeff[i] = 0.0; xv1[i]=0; xv2[i]=0; yv1[i]=0; yv2[i]=0; } aCoeff[0]= 1.0; bCoeff[0]= 1.0; int k = 0; int n = order; int pairs = n/2; if (odd(order)) { // first subfilter is first order aCoeff[1] = - z[1]; bCoeff[1] = - pReal[1]; k = 1; } for (int p = 1; p <= pairs; p++) { int m = 2*p - 1 + k; double alpha1 = - (z[m] + z[m+1]); double alpha2 = z[m]*z[m+1]; double beta1 = - 2.0*pReal[m]; double beta2 = sqr(pReal[m]) + sqr(pImag[m]); newA[1] = aCoeff[1] + alpha1*aCoeff[0]; newB[1] = bCoeff[1] + beta1 *bCoeff[0]; for (int i = 2; i <= n; i++) { newA[i] = aCoeff[i] + alpha1*aCoeff[i-1] + alpha2*aCoeff[i-2]; newB[i] = bCoeff[i] + beta1 *bCoeff[i-1] + beta2 *bCoeff[i-2]; } for (int i = 1; i <= n; i++) { aCoeff[i] = newA[i]; bCoeff[i] = newB[i]; } } //RL: Make table look like York, reverse order and invert sign float *tmp = new float[order+1]; for (int i=0; i<=order; i++) tmp[i] = -bCoeff[order-i]; bCoeff = tmp; ready=true; //Ok to call filter() //Testing if (false) { for (int i=0; i<=order; i++) { qDebug()<<"aCoeff:["<<i<<"] = "<<aCoeff[i]<<" : "<<"bCoeff:["<<i<<"] = "<<bCoeff[i]; } } }
short ptype_distance(short ptyp, short f, short t) { short side, piece; short colf, colt, rowf, rowt, dcol, drow; if (f == t) return 0; piece = piece_of_ptype[ptyp]; side = side_of_ptype[ptyp]; dcol = (colt = ccol(t)) - (colf = ccol(f)); drow = (rowt = crow(t)) - (rowf = crow(f)); switch (piece) { case pawn: if ((dcol != 0) || (drow < 1)) return CANNOT_REACH; else return drow; case lance: if ((dcol != 0) || (drow < 1)) return CANNOT_REACH; else return 1; case knight: if (odd(drow) || (odd(drow / 2) != odd(dcol))) return CANNOT_REACH; else if ((drow == 0) || ((drow / 2) < abs(dcol))) return CANNOT_REACH; else return (drow / 2); case silver: if (drow > 0) { if (odd(drow) == odd(dcol)) { return max(abs(drow), abs(dcol)); } else { if (abs(dcol) <= drow) return drow; else return (max(abs(drow), abs(dcol)) + 1); } } else { if (odd(drow) == odd(dcol)) return (max(abs(drow), abs(dcol))); else return (max(abs(drow) + 1, abs(dcol)) + 1); }; case gold: case ppawn: case pknight: case plance: case psilver: if (abs(dcol) == 0) return (abs(drow)); else if (drow >= 0) return max(drow, abs(dcol)); else return (abs(dcol) - drow); case bishop: if (odd(dcol) != odd(drow)) return CANNOT_REACH; else return ((abs(dcol) == abs(drow)) ? 1 : 2); case pbishop: if (odd(dcol) != odd(drow)) { if ((abs(dcol) <= 1) && (abs(drow) <= 1)) return 1; else if (abs(abs(dcol) - abs(drow)) == 1) return 2; else return 3; } else { return ((abs(dcol) == abs(drow)) ? 1 : 2); } case rook: if ((dcol == 0) || (drow == 0)) return 1; else return 2; case prook: if ((dcol == 0) || (drow == 0)) return 1; else if ((abs(dcol) == 1) && (abs(drow) == 1)) return 1; else return 2; case king: return max(abs(drow), abs(dcol)); default: /* should never occur */ return (CANNOT_REACH); } }
static WORD GreaterEven(int i) { return odd(i) ? i + 1 : i + 2; }
/* * vSpitList - Split the list in two */ static void vSpitList(list_mem_type **ppAnchorCurr, list_mem_type **ppAnchorNext, ULONG ulListLen) { list_mem_type *pCurr; long lCharsToGo, lBytesTooFar; fail(ppAnchorCurr == NULL); fail(ppAnchorNext == NULL); fail(ulListLen > (ULONG)LONG_MAX); pCurr = NULL; lCharsToGo = (long)ulListLen; lBytesTooFar = -1; if (ulListLen != 0) { DBG_DEC(ulListLen); for (pCurr = *ppAnchorCurr; pCurr != NULL; pCurr = pCurr->pNext) { NO_DBG_DEC(pCurr->tInfo.ulLength); fail(pCurr->tInfo.ulLength == 0); fail(pCurr->tInfo.ulLength > (ULONG)LONG_MAX); if (pCurr->tInfo.bUsesUnicode) { fail(odd(pCurr->tInfo.ulLength)); lCharsToGo -= (long)(pCurr->tInfo.ulLength / 2); if (lCharsToGo < 0) { lBytesTooFar = -2 * lCharsToGo; } } else { lCharsToGo -= (long)pCurr->tInfo.ulLength; if (lCharsToGo < 0) { lBytesTooFar = -lCharsToGo; } } if (lCharsToGo <= 0) { break; } } } /* Split the list */ if (ulListLen == 0) { /* Current blocklist is empty */ *ppAnchorNext = *ppAnchorCurr; *ppAnchorCurr = NULL; } else if (pCurr == NULL) { /* No blocks for the next list */ *ppAnchorNext = NULL; } else if (lCharsToGo == 0) { /* Move the integral number of blocks to the next list */ *ppAnchorNext = pCurr->pNext; pCurr->pNext = NULL; } else { /* Split the part current block list, part next block list */ DBG_DEC(lBytesTooFar); fail(lBytesTooFar <= 0); *ppAnchorNext = xmalloc(sizeof(list_mem_type)); DBG_HEX(pCurr->tInfo.ulFileOffset); (*ppAnchorNext)->tInfo.ulFileOffset = pCurr->tInfo.ulFileOffset + pCurr->tInfo.ulLength - lBytesTooFar; DBG_HEX((*ppAnchorNext)->tInfo.ulFileOffset); DBG_HEX(pCurr->tInfo.ulCharPos); (*ppAnchorNext)->tInfo.ulCharPos = pCurr->tInfo.ulCharPos + pCurr->tInfo.ulLength - lBytesTooFar; DBG_HEX((*ppAnchorNext)->tInfo.ulCharPos); (*ppAnchorNext)->tInfo.ulLength = (ULONG)lBytesTooFar; pCurr->tInfo.ulLength -= (ULONG)lBytesTooFar; (*ppAnchorNext)->tInfo.bUsesUnicode = pCurr->tInfo.bUsesUnicode; (*ppAnchorNext)->tInfo.usPropMod = pCurr->tInfo.usPropMod; /* Move the integral number of blocks to the next list */ (*ppAnchorNext)->pNext = pCurr->pNext; pCurr->pNext = NULL; } } /* end of vSpitList */
static WORD GreaterOdd(int i) { return odd(i) ? i + 2 : i + 1; }
void executeInstruction() { switch(ir.op) { case 1: lit(); break; case 2: opr(); break; case 3: lod(); break; case 4: sto(); break; case 5: cal(); break; case 6: inc(); break; case 7: jmp(); break; case 8: jpc(); break; case 9: sio(); default: break; } void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); halt = 1; break; } } }
static WORD EmbeddingDirection(int level) { return odd(level) ? R : L; }
void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); sio3(); } }
/*------------------------------------------------------------------------ Function: resolveWeak Resolves the directionality of numeric and other weak character types Implements rules X10 and W1-W6 of the Unicode Bidirectional Algorithm. Input: Array of embedding levels Character count In/Out: Array of directional classes Note: On input only these directional classes are expected AL, HL, R, L, ON, BN, NSM, AN, EN, ES, ET, CS, ------------------------------------------------------------------------*/ static void resolveWeak(int baselevel, WORD *pcls, WORD *plevel, int cch) { int state = odd(baselevel) ? xr : xl; int cls; int level = baselevel; int action, clsRun, clsNew; int cchRun = 0; int ich = 0; for (; ich < cch; ich++) { /* ignore boundary neutrals */ if (pcls[ich] == BN) { /* must flatten levels unless at a level change; */ plevel[ich] = level; /* lookahead for level changes */ if (ich + 1 == cch && level != baselevel) { /* have to fixup last BN before end of the loop, since * its fix-upped value will be needed below the assert */ pcls[ich] = EmbeddingDirection(level); } else if (ich + 1 < cch && level != plevel[ich+1] && pcls[ich+1] != BN) { /* fixup LAST BN in front / after a level run to make * it act like the SOR/EOR in rule X10 */ int newlevel = plevel[ich+1]; if (level > newlevel) { newlevel = level; } plevel[ich] = newlevel; /* must match assigned level */ pcls[ich] = EmbeddingDirection(newlevel); level = plevel[ich+1]; } else { /* don't interrupt runs */ if (cchRun) { cchRun++; } continue; } } ASSERT(pcls[ich] <= BN); cls = pcls[ich]; action = actionWeak[state][cls]; /* resolve the directionality for deferred runs */ clsRun = GetDeferredType(action); if (clsRun != XX) { SetDeferredRun(pcls, cchRun, ich, clsRun); cchRun = 0; } /* resolve the directionality class at the current location */ clsNew = GetResolvedType(action); if (clsNew != XX) pcls[ich] = clsNew; /* increment a deferred run */ if (IX & action) cchRun++; state = stateWeak[state][cls]; } /* resolve any deferred runs * use the direction of the current level to emulate PDF */ cls = EmbeddingDirection(level); /* resolve the directionality for deferred runs */ clsRun = GetDeferredType(actionWeak[state][cls]); if (clsRun != XX) SetDeferredRun(pcls, cchRun, ich, clsRun); }
void bench(int detailed_printout, size_t array_size) { int i ; int mednum ; pixelvalue med[N_METHODS] ; clock_t chrono ; double elapsed ; pixelvalue * array_init, * array ; /* * initialize random generator with PID * This is the only Unix-ish thing, replace this by any * initialization scheme you wish. */ srand48(getpid()) ; if (detailed_printout) { printf("generating numbers...\n") ; fflush(stdout) ; } if (array_size<1) array_size = BIG_NUM ; if (detailed_printout) { printf("array size: %ld\n", (long)array_size) ; } else { printf("%ld\t", (long)array_size) ; } array_init = malloc(array_size * sizeof(pixelvalue)) ; array = malloc(array_size * sizeof(pixelvalue)) ; if (array_init==NULL || array==NULL) { printf("memory allocation failure: aborting\n") ; return ; } for (i=0 ; i<array_size; i++) { array_init[i] = (pixelvalue)(lrand48() % MAX_ARRAY_VALUE) ; } mednum = 0 ; /* benchmark the quick select sort */ memcpy(array, array_init, array_size * sizeof(pixelvalue)) ; if (detailed_printout) { printf("quick select :\t") ; fflush(stdout) ; } chrono = clock() ; med[mednum] = quick_select(array, array_size) ; elapsed = (double)(clock() - chrono) / (double)CLOCKS_PER_SEC ; if (detailed_printout) { printf("%5.3f sec\t", elapsed) ; fflush(stdout) ; printf("med %g\n", (double)med[mednum]) ; fflush(stdout) ; } else { printf("%5.3f\t", elapsed) ; fflush(stdout) ; } mednum++ ; /* benchmark WIRTH */ memcpy(array, array_init, array_size * sizeof(pixelvalue)) ; if (detailed_printout) { printf("WIRTH median :\t") ; fflush(stdout) ; } chrono = clock() ; med[mednum] = median_WIRTH(array, array_size) ; elapsed = (double)(clock() - chrono) / (double)CLOCKS_PER_SEC ; if (detailed_printout) { printf("%5.3f sec\t", elapsed) ; fflush(stdout) ; printf("med %g\n", (double)med[mednum]) ; fflush(stdout) ; } else { printf("%5.3f\t", elapsed) ; fflush(stdout) ; } mednum++ ; /* benchmark the AHU sort */ memcpy(array, array_init, array_size * sizeof(pixelvalue)) ; if (detailed_printout) { printf("AHU median :\t") ; fflush(stdout) ; } chrono = clock() ; med[mednum] = median_AHU(array, array_size) ; elapsed = (double)(clock() - chrono) / (double)CLOCKS_PER_SEC ; if (detailed_printout) { printf("%5.3f sec\t", elapsed) ; fflush(stdout) ; printf("med %g\n", (double)med[mednum]) ; fflush(stdout) ; } else { printf("%5.3f\t", elapsed) ; fflush(stdout) ; } mednum++ ; /* benchmark torben's method */ memcpy(array, array_init, array_size * sizeof(pixelvalue)) ; if (detailed_printout) { printf("torben :\t") ; fflush(stdout) ; } chrono = clock() ; med[mednum] = torben(array, array_size) ; elapsed = (double)(clock() - chrono) / (double)CLOCKS_PER_SEC ; if (detailed_printout) { printf("%5.3f sec\t", elapsed) ; fflush(stdout) ; printf("med %g\n", (double)med[mednum]) ; fflush(stdout) ; } else { printf("%5.3f\t", elapsed) ; fflush(stdout) ; } mednum++ ; /* benchmark the eclipse fast pixel sort */ memcpy(array, array_init, array_size * sizeof(pixelvalue)) ; if (detailed_printout) { printf("fast pixel sort :\t") ; fflush(stdout) ; } chrono = clock() ; pixel_qsort(array, array_size) ; elapsed = (double)(clock() - chrono) / (double)CLOCKS_PER_SEC ; if (odd(array_size)) { med[mednum] = array[array_size/2] ; } else { med[mednum] = array[(array_size/2) -1] ; } if (detailed_printout) { printf("%5.3f sec\t", elapsed) ; fflush(stdout) ; printf("med %g\n", (double)med[mednum]) ; fflush(stdout) ; } else { printf("%5.3f\t", elapsed) ; fflush(stdout) ; } mednum++ ; free(array) ; free(array_init) ; for (i=1 ; i<N_METHODS ; i++) { if (med[i-1]!=med[i]) { printf("diverging median values!\n") ; fflush(stdout) ; } } printf("\n") ; fflush(stdout) ; return ; }
bool alternate(int i) { if (i>=0) return even(i); else return odd(i); }
void docharacters ( void ) { byte c ; indextype k ; integer ai ; sortptr = 0 ; {register integer for_end; c = bc ;for_end = ec ; if ( c <= for_end) do if ( tfm [4 * ( charbase + c ) ]> 0 ) { if ( charsonline == 8 ) { { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 1 ; } else { if ( charsonline > 0 ) putc ( ' ' , stderr ); if ( verbose ) charsonline = charsonline + 1 ; } if ( verbose ) printoctal ( c ) ; left () ; Fputs ( plfile , "CHARACTER" ) ; outchar ( c ) ; outln () ; { left () ; Fputs ( plfile , "CHARWD" ) ; if ( tfm [4 * ( charbase + c ) ]>= nw ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } fprintf ( stderr , "%s%s", "Width" , " index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I reset it to zero." ) ; } else outfix ( 4 * ( widthbase + tfm [4 * ( charbase + c ) ]) ) ; right () ; } if ( ( tfm [4 * ( charbase + c ) + 1 ]/ 16 ) > 0 ) { if ( ( tfm [4 * ( charbase + c ) + 1 ]/ 16 ) >= nh ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } fprintf ( stderr , "%s%s", "Height" , " index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I reset it to zero." ) ; } else { left () ; Fputs ( plfile , "CHARHT" ) ; outfix ( 4 * ( heightbase + ( tfm [4 * ( charbase + c ) + 1 ]/ 16 ) ) ) ; right () ; } } if ( ( tfm [4 * ( charbase + c ) + 1 ]% 16 ) > 0 ) { if ( ( tfm [4 * ( charbase + c ) + 1 ]% 16 ) >= nd ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } fprintf ( stderr , "%s%s", "Depth" , " index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I reset it to zero." ) ; } else { left () ; Fputs ( plfile , "CHARDP" ) ; outfix ( 4 * ( depthbase + ( tfm [4 * ( charbase + c ) + 1 ]% 16 ) ) ) ; right () ; } } if ( ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) > 0 ) { if ( ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) >= ni ) { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } fprintf ( stderr , "%s%s", "Italic correction" , " index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I reset it to zero." ) ; } else { left () ; Fputs ( plfile , "CHARIC" ) ; outfix ( 4 * ( italicbase + ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) ) ) ; right () ; } } switch ( ( tfm [4 * ( charbase + c ) + 2 ]% 4 ) ) {case 0 : ; break ; case 1 : { left () ; Fputs ( plfile , "COMMENT" ) ; outln () ; i = tfm [4 * ( charbase + c ) + 3 ]; r = 4 * ( ligkernbase + ( i ) ) ; if ( tfm [r ]> 128 ) i = 256 * tfm [r + 2 ]+ tfm [r + 3 ]; do { { k = 4 * ( ligkernbase + ( i ) ) ; if ( tfm [k ]> 128 ) { if ( 256 * tfm [k + 2 ]+ tfm [k + 3 ]>= nl ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s\n", "Bad TFM file: " , "Ligature unconditional stop command address is too big." ) ; } } else if ( tfm [k + 2 ]>= 128 ) { if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) { if ( tfm [k + 1 ]!= boundarychar ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Kern step for" , " nonexistent character " ) ; printoctal ( tfm [k + 1 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 1 ]= bc ; } } left () ; Fputs ( plfile , "KRN" ) ; outchar ( tfm [k + 1 ]) ; r = 256 * ( tfm [k + 2 ]- 128 ) + tfm [k + 3 ]; if ( r >= nk ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s\n", "Bad TFM file: " , "Kern index too large." ) ; } Fputs ( plfile , " R 0.0" ) ; } else outfix ( 4 * ( kernbase + r ) ) ; right () ; } else { if ( ( ( tfm [k + 1 ]< bc ) || ( tfm [k + 1 ]> ec ) || ( tfm [4 * ( charbase + tfm [k + 1 ]) ]== 0 ) ) ) { if ( tfm [k + 1 ]!= boundarychar ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Ligature step for" , " nonexistent character " ) ; printoctal ( tfm [k + 1 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 1 ]= bc ; } } if ( ( ( tfm [k + 3 ]< bc ) || ( tfm [k + 3 ]> ec ) || ( tfm [4 * ( charbase + tfm [k + 3 ]) ]== 0 ) ) ) { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Ligature step produces the" , " nonexistent character " ) ; printoctal ( tfm [k + 3 ]) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } tfm [k + 3 ]= bc ; } left () ; r = tfm [k + 2 ]; if ( ( r == 4 ) || ( ( r > 7 ) && ( r != 11 ) ) ) { fprintf ( stderr , "%s\n", "Ligature step with nonstandard code changed to LIG" ) ; r = 0 ; tfm [k + 2 ]= 0 ; } if ( r % 4 > 1 ) putc ( '/' , plfile ); Fputs ( plfile , "LIG" ) ; if ( odd ( r ) ) putc ( '/' , plfile ); while ( r > 3 ) { putc ( '>' , plfile ); r = r - 4 ; } outchar ( tfm [k + 1 ]) ; outchar ( tfm [k + 3 ]) ; right () ; } if ( tfm [k ]> 0 ) { if ( level == 1 ) { if ( tfm [k ]>= 128 ) Fputs ( plfile , "(STOP)" ) ; else { count = 0 ; {register integer for_end; ai = i + 1 ;for_end = i + tfm [k ]; if ( ai <= for_end) do if ( activity [ai ]== 2 ) count = count + 1 ; while ( ai++ < for_end ) ;} fprintf ( plfile , "%s%ld%c", "(SKIP D " , (long)count , ')' ) ; } outln () ; } } } if ( tfm [k ]>= 128 ) i = nl ; else i = i + 1 + tfm [k ]; } while ( ! ( i >= nl ) ) ; right () ; } break ; case 2 : { r = tfm [4 * ( charbase + c ) + 3 ]; if ( ( ( r < bc ) || ( r > ec ) || ( tfm [4 * ( charbase + r ) ]== 0 ) ) ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s%s", "Bad TFM file: " , "Character list link to" , " nonexistent character " ) ; printoctal ( r ) ; { putc ( '.' , stderr ); putc ( '\n', stderr ); } } tfm [4 * ( charbase + c ) + 2 ]= 4 * ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) + 0 ; } else { while ( ( r < c ) && ( ( tfm [4 * ( charbase + r ) + 2 ]% 4 ) == 2 ) ) r = tfm [4 * ( charbase + r ) + 3 ]; if ( r == c ) { { perfect = false ; if ( charsonline > 0 ) { putc ( ' ' , stderr ); putc ( '\n', stderr ); } charsonline = 0 ; fprintf ( stderr , "%s%s\n", "Bad TFM file: " , "Cycle in a character list!" ) ; } Fputs ( stderr , "Character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " now ends the list." ) ; tfm [4 * ( charbase + c ) + 2 ]= 4 * ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) + 0 ; } else { left () ; Fputs ( plfile , "NEXTLARGER" ) ; outchar ( tfm [4 * ( charbase + c ) + 3 ]) ; right () ; } } } break ; case 3 : if ( tfm [4 * ( charbase + c ) + 3 ]>= ne ) { { perfect = false ; { putc ( ' ' , stderr ); putc ( '\n', stderr ); } fprintf ( stderr , "%s%s", "Extensible" , " index for character " ) ; printoctal ( c ) ; fprintf ( stderr , "%s\n", " is too large;" ) ; fprintf ( stderr , "%s\n", "so I reset it to zero." ) ; } tfm [4 * ( charbase + c ) + 2 ]= 4 * ( tfm [4 * ( charbase + c ) + 2 ]/ 4 ) + 0 ; } else { left () ; Fputs ( plfile , "VARCHAR" ) ; outln () ; {register integer for_end; k = 0 ;for_end = 3 ; if ( k <= for_end) do if ( ( k == 3 ) || ( tfm [4 * ( extenbase + tfm [4 * ( charbase + c ) + 3 ]) + k ]> 0 ) ) { left () ; switch ( k ) {case 0 : Fputs ( plfile , "TOP" ) ; break ; case 1 : Fputs ( plfile , "MID" ) ; break ; case 2 : Fputs ( plfile , "BOT" ) ; break ; case 3 : Fputs ( plfile , "REP" ) ; break ; } if ( ( ( tfm [4 * ( extenbase + tfm [4 * ( charbase + c ) + 3 ]) + k ]< bc ) || ( tfm [4 * ( extenbase + tfm [4 * ( charbase + c ) + 3 ]) + k ]> ec ) || ( tfm [4 * ( charbase + tfm [4 * ( extenbase + tfm [4 * ( charbase + c ) + 3 ]) + k ] ) ]== 0 ) ) ) outchar ( c ) ; else outchar ( tfm [4 * ( extenbase + tfm [4 * ( charbase + c ) + 3 ]) + k ]) ; right () ; } while ( k++ < for_end ) ;} right () ; } break ; } right () ; } while ( c++ < for_end ) ;} }
void GL_ST7735::drawConicHelper(int xs, int ys, int xe, int ye, int color) { #if (DEBUG) { const char *fmt = "GL_ST7735::drawConicHelper called with %7d %7d %7d %7d %7d" ; char buf[snprintf(NULL, 0, fmt, xs, ys, xe, ye, color) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, xs, ys, xe, ye, color) ; Serial.println(buf) ; } #endif #if (DEBUG) { const char *fmt = "GL_ST7735::drawConicHelper -1- %12ld %12ld %12ld %12ld %12ld %12ld" ; char buf[snprintf(NULL, 0, fmt, A,B,C,D,E,F) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, A,B,C,D,E,F) ; Serial.println(buf) ; } #endif A *= 4; B *= 4; C *= 4; D *= 4; E *= 4; F *= 4; #if (DEBUG) { const char *fmt = "GL_ST7735::drawConicHelper -2- %12ld %12ld %12ld %12ld %12ld %12ld" ; char buf[snprintf(NULL, 0, fmt, A,B,C,D,E,F) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, A,B,C,D,E,F) ; Serial.println(buf) ; } #endif // Translate start point to origin... F = A*xs*xs + B*xs*ys + C*ys*ys + D*xs + E*ys + F; D = D + 2 * A * xs + B * ys; E = E + B * xs + 2 * C * ys; // Work out starting octant int octant = getOctant(D,E); int dxS = SIDEx[octant]; int dyS = SIDEy[octant]; int dxD = DIAGx[octant]; int dyD = DIAGy[octant]; long d,u,v; #if (DEBUG) { const char *fmt = "Before switch, octant = %d" ; char buf[snprintf(NULL, 0, fmt, octant) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, octant) ; Serial.println(buf) ; } #endif if (octant == 1) { d = A + B / 2 + C / 4 + D + E / 2 + F; u = A + B / 2 + D; v = u + E; } else if (octant == 2) { d = A / 4 + B / 2 + C + D / 2 + E + F; u = B / 2 + C + E; v = u + D; } else if (octant == 3) { d = A / 4 - B / 2 + C - D / 2 + E + F; u = -B / 2 + C + E; v = u - D; } else if (octant == 4) { d = A - B / 2 + C / 4 - D + E / 2 + F; u = A - B / 2 - D; v = u + E; } else if (octant == 5) { d = A + B / 2 + C / 4 - D - E / 2 + F; u = A + B / 2 - D; v = u - E; } else if (octant == 6) { d = A / 4 + B / 2 + C - D / 2 - E + F; u = B / 2 + C - E; v = u - D; } else if (octant == 7) { d = A / 4 - B / 2 + C + D / 2 - E + F; u = -B / 2 + C - E; v = u + D; } else if (octant == 8) { d = A - B / 2 + C / 4 + D - E / 2 + F; u = A - B / 2 + D; v = u - E; } else { d=0 ; u=0 ; v=0 ; const char *fmt = "FUNNY OCTANT"; char buf[snprintf(NULL, 0, fmt) + 1]; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt); Serial.println(buf); while (true) {} ; } // switch (octant) { // case 1: // d = A + B / 2 + C / 4 + D + E / 2 + F; // u = A + B / 2 + D; // v = u + E; // break; // case 2: // d = A / 4 + B / 2 + C + D / 2 + E + F; // u = B / 2 + C + E; // v = u + D; // break; // case 3: // d = A / 4 - B / 2 + C - D / 2 + E + F; // u = -B / 2 + C + E; // v = u - D; // break; // case 4: // d = A - B / 2 + C / 4 - D + E / 2 + F; // u = A - B / 2 - D; // v = u + E; // break; // case 5: // d = A + B / 2 + C / 4 - D - E / 2 + F; // u = A + B / 2 - D; // v = u - E; // break; // case 6: // d = A / 4 + B / 2 + C - D / 2 - E + F; // u = B / 2 + C - E; // v = u - D; // break; // case 7: // d = A / 4 - B / 2 + C + D / 2 - E + F; // u = -B / 2 + C - E; // v = u + D; // break; // case 8: // d = A - B / 2 + C / 4 + D - E / 2 + F; // u = A - B / 2 + D; // v = u - E; // break; // default: // d=0 ; u=0 ; v=0 ; // const char *fmt = "FUNNY OCTANT"; // char buf[snprintf(NULL, 0, fmt) + 1]; // // // // note +1 for terminating null byte // // // snprintf(buf, sizeof buf, fmt); // Serial.println(buf); // while (true) {} ; // break ; // } #if (DEBUG) { const char *fmt = "After switch, octant = %d" ; char buf[snprintf(NULL, 0, fmt, octant) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, octant) ; Serial.println(buf) ; } #endif long k1sign = dyS*dyD; long k1 = 2 * (A + k1sign * (C - A)); long Bsign = dxD*dyD; long k2 = k1 + Bsign * B; long k3 = 2 * (A + C + Bsign * B); // Work out gradient at endpoint long gxe = xe - xs; long gye = ye - ys; long gx = 2*A*gxe + B*gye + D; long gy = B*gxe + 2*C*gye + E; int octantCount = getOctant(gx,gy) - octant; if (octantCount < 0) octantCount = octantCount + 8; else if (octantCount==0) if((xs>xe && dxD>0) || (ys>ye && dyD>0) || (xs<xe && dxD<0) || (ys<ye && dyD<0)) octantCount +=8; #if (DEBUG) { const char *fmt = "octantCount = %d\n" ; char buf[snprintf(NULL, 0, fmt, octantCount) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, octantCount) ; Serial.print(buf) ; } #endif long x = xs; long y = ys; while (octantCount > 0) { #if (DEBUG) { const char *fmt = "-- %d -------------------------\n" ; char buf[snprintf(NULL, 0, fmt, octant) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, octant) ; Serial.print(buf) ; } #endif if (odd(octant)) { while (2*v <= k2) { // Plot this point drawPixel(x, y, color) ; // Are we inside or outside? #if (DEBUG) { const char *fmt = "x = %ld y = %ld d = %ld\n" ; char buf[snprintf(NULL, 0, fmt, x,y,d) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, x,y,d) ; Serial.print(buf) ; } #endif if (d < 0) { // Inside x = x + dxS; y = y + dyS; u = u + k1; v = v + k2; d = d + u; } else { // outside x = x + dxD; y = y + dyD; u = u + k2; v = v + k3; d = d + v; } } d = d - u + v/2 - k2/2 + 3*k3/8; // error (^) in Foley and van Dam p 959, "2nd ed, revised 5th printing" u = -u + v - k2/2 + k3/2; v = v - k2 + k3/2; k1 = k1 - 2*k2 + k3; k2 = k3 - k2; int tmp = dxS; dxS = -dyS; dyS = tmp; } else { // Octant is even while (2*u < k2) { // Plot this point drawPixel(x, y, color) ; #if (DEBUG) { const char *fmt = "x = %ld y = %ld d = %ld\n" ; char buf[snprintf(NULL, 0, fmt, x,y,d) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, x,y,d) ; Serial.print(buf) ; } #endif // Are we inside or outside? if (d > 0) { // Outside x = x + dxS; y = y + dyS; u = u + k1; v = v + k2; d = d + u; } else { // Inside x = x + dxD; y = y + dyD; u = u + k2; v = v + k3; d = d + v; } } long tmpdk = k1 - k2; d = d + u - v + tmpdk; v = 2*u - v + tmpdk; u = u + tmpdk; k3 = k3 + 4*tmpdk; k2 = k1 + tmpdk; int tmp = dxD; dxD = -dyD; dyD = tmp; } octant = (octant&7)+1; octantCount--; } // Draw final octant until we reach the endpoint #if (DEBUG) { const char *fmt = "-- %d (final) -----------------\n" ; char buf[snprintf(NULL, 0, fmt, octant) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, octant) ; Serial.print(buf) ; } #endif if (odd(octant)) { while (2*v <= k2) { // Plot this point drawPixel(x, y, color) ; if (x == xe && y == ye) break; #if (DEBUG) { const char *fmt = "x = %ld y = %ld d = %ld\n" ; char buf[snprintf(NULL, 0, fmt, x,y,d) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, x,y,d) ; Serial.print(buf) ; } #endif // Are we inside or outside? if (d < 0) { // Inside x = x + dxS; y = y + dyS; u = u + k1; v = v + k2; d = d + u; } else { // outside x = x + dxD; y = y + dyD; u = u + k2; v = v + k3; d = d + v; } } } else { // Octant is even while ((2*u < k2)) { // Plot this point drawPixel(x, y, color) ; if (x == xe && y == ye) break; #if (DEBUG) { const char *fmt = "x = %ld y = %ld d = %ld\n" ; char buf[snprintf(NULL, 0, fmt, x,y,d) + 1] ; // // note +1 for terminating null byte // snprintf(buf, sizeof buf, fmt, x,y,d) ; Serial.print(buf) ; } #endif // Are we inside or outside? if (d > 0) { // Outside x = x + dxS; y = y + dyS; u = u + k1; v = v + k2; d = d + u; } else { // Inside x = x + dxD; y = y + dyD; u = u + k2; v = v + k3; d = d + v; } } } }
bool even(unsigned x) { return (x == 0) ? true : odd(x - 1); }
void get_hexagon_origin(hex_t *h, double *dx, double *dy) { int x = h->x; int y = h->y; *dx = sq3*x + (odd(y) ? (sq3/2) : 0); *dy = (3.0/2)*y; }
inline constexpr bool even(const T a) { return !odd(a); }
void IIRFilter::setFilterType(int ft) { filterType = ft; if ((filterType == BP) && odd(order)) order++; ready = false; }