static void scs_tan(double x, scs_ptr res_scs){ scs_t x_scs; scs_t x2; int i; scs_t y_scs; int N; scs_set_d(x_scs, x); N = rem_pio2_scs(y_scs, x_scs); /* x (=sc2) is in [-Pi/4,Pi/4] */ N = N & 1; /* extract the last bit of N */ scs_square(x2, y_scs); scs_mul(res_scs, tan_scs_poly_ptr[0], x2); for(i=1; i<(DEGREE_TAN_SCS-1)/2; i++){ /* The last coeff is not read from the file. */ scs_add(res_scs, tan_scs_poly_ptr[i], res_scs); scs_mul(res_scs, res_scs, x2); } scs_mul(res_scs, res_scs, y_scs); scs_add(res_scs, y_scs, res_scs); if(N==1) { scs_inv(res_scs, res_scs); res_scs->sign = -res_scs->sign; } }
static void scs_cos(scs_ptr x){ scs_t res_scs; scs_t x2; int i; scs_square(x2, x); scs_mul(res_scs, cos_scs_poly_ptr[0], x2); for(i=1; i<DEGREE_COS_SCS/2; i++){ scs_add(res_scs, cos_scs_poly_ptr[i], res_scs); scs_mul(res_scs, res_scs, x2); } /* The last coefficient is exactly one and is not read from the file */ scs_add(x, res_scs, SCS_ONE); return ; }
static void scs_sin(scs_ptr x){ scs_t res_scs; scs_t x2; int i; scs_square(x2, x); scs_mul(res_scs, sin_scs_poly_ptr[0], x2); for(i=1; i<(DEGREE_SIN_SCS-1)/2; i++){ /* Last coeff is one, not read from the file*/ scs_add(res_scs, sin_scs_poly_ptr[i], res_scs); scs_mul(res_scs, res_scs, x2); } scs_mul(res_scs, res_scs, x); scs_add(x, x, res_scs); return; }
/* This one is working but is slower than the first one */ void cosine(scs_ptr x){ scs_t res_scs; scs_t x2; int i; /* x < 2^-75 => cos(x)~1 (with accuracy 2^-150,999), when rounding to nearest, here we consider x< 2^-90 */ if(X_IND < -3){ scs_sub(x, SCS_ONE,x); return; } /* Polynomial evaluation */ scs_square(x2, x); scs_mul(res_scs, constt_poly_ptr[0], x2); for(i=1; i<16; i++){ scs_add(res_scs, constt_poly_ptr[i], res_scs); scs_mul(res_scs, res_scs, x2); } scs_add(x, res_scs, SCS_ONE); return ; }
static void scs_atan(scs_ptr res_scs, scs_ptr x){ scs_t X_scs, denom1_scs, denom2_scs, poly_scs, X2; scs_t atanbhihi,atanbhilo, atanblo, atanbhi, atanb; scs_t bsc_ptr; db_number db; double test; int k, i=31; scs_get_d(&db.d, x); #if EVAL_PERF crlibm_second_step_taken++; #endif /* test if x as to be reduced */ if (db.d > MIN_REDUCTION_NEEDED) { /* Compute i so that x E [a[i],a[i+1]] */ if (db.d < arctan_table[i][A].d) i-= 16; else i+=16; if (db.d < arctan_table[i][A].d) i-= 8; else i+= 8; if (db.d < arctan_table[i][A].d) i-= 4; else i+= 4; if (db.d < arctan_table[i][A].d) i-= 2; else i+= 2; if (db.d < arctan_table[i][A].d) i-= 1; else if (i<61) i+= 1; if (db.d < arctan_table[i][A].d) i-= 1; /* evaluate X = (x - b(i)) / (1 + x*b(i)) */ scs_set_d(bsc_ptr, arctan_table[i][B].d); scs_mul(denom1_scs,bsc_ptr,x); scs_add(denom2_scs,denom1_scs,SCS_ONE); scs_sub(X_scs,x,bsc_ptr); scs_div(X_scs,X_scs,denom2_scs); scs_get_d(&test,X_scs); /* Polynomial evaluation of atan(X) , X = (x-b(i)) / (1+ x*b(i)) */ scs_square(X2, X_scs); scs_set(res_scs, constant_poly_ptr[0]); for(k=1; k < 10; k++) { /* we use Horner expression */ scs_mul(res_scs, res_scs, X2); scs_add(res_scs, constant_poly_ptr[k], res_scs); } scs_mul(poly_scs, res_scs, X_scs); /* reconstruction : */ /* 1st we load atan ( b[i] ) in a scs*/ scs_set_d( atanbhihi , arctan_table[i][ATAN_BHI].d); scs_set_d( atanbhilo , arctan_table[i][ATAN_BLO].d); scs_set_d( atanblo , atan_blolo[i].d); scs_add(atanbhi,atanbhihi,atanbhilo); scs_add(atanb,atanbhi,atanblo); scs_add(res_scs,atanb, poly_scs); return; } else { /* no reduction needed */ /* Polynomial evaluation of atan(x) */ scs_square(X2, x); scs_set(res_scs, constant_poly_ptr[0]); for(k=1; k < 10; k++) { /* we use Horner expression */ scs_mul(res_scs, res_scs, X2); scs_add(res_scs, constant_poly_ptr[k], res_scs); } scs_mul(res_scs, res_scs, x); return; } }