Ejemplo n.º 1
0
/* 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;
    }
}