Example #1
0
/*************************************************************
 *************************************************************
 *               ROUNDED  TO NEAREST			     *
 *************************************************************
 *************************************************************/
double scs_cos_rn(double x){ 
  scs_t sc1, sc2;
  double resd;
  int N;
#if EVAL_PERF
	crlibm_second_step_taken++;
#endif

  scs_set_d(sc1, x);
  N = rem_pio2_scs(sc2, sc1);
  N = N & 0x0000003;		/* extract the 2 last bits of  N */
  switch (N){
  case 0:
    cosine(sc2);
    scs_get_d(&resd, sc2);
    return resd;
  case 1:
    sine(sc2);
    scs_get_d(&resd, sc2);
    return -resd;
  case 2:
    cosine(sc2);
    scs_get_d(&resd, sc2);
    return -resd;
  case 3:
    sine(sc2);
    scs_get_d(&resd, sc2);
    return resd;
  default:
    fprintf(stderr,"ERREUR: %d is not a valid value in s_cos \n", N);
    return 0.0;
  }
  
}
Example #2
0
void scs_get_std( scs_ptr x){
  int i; 
  db_number d;

  scs_get_d(&d.d, x);
  printf("Exception : %e \n", X_EXP);
  printf("Index= %d   \n Sign=  %d \n Double value= %.30e   \n Hex mantissa= %x %x\n", 
	 X_IND, X_SGN, d.d, d.i[HI], d.i[LO]);
  for(i=0;i<SCS_NB_WORDS;i++){
    printf("  D %d :  %8x %20u \n",i, X_HW[i], X_HW[i]);
  }
}
double scs_tan_rn(double x){
  scs_t res_scs;
  double resd;

#if EVAL_PERF
  crlibm_second_step_taken++;
#endif

  scs_tan(x,res_scs);
  scs_get_d(&resd, res_scs);
  return resd;
}
double scs_atanpi_rn(double x){
  /* This function does NOT compute atanpi(x) correctly if it isn't
   * called in atanpi_rn()
   */
  scs_t sc1;
  scs_t res_scs;
  db_number res;
  int sign =1;

  res.d = x;

  if (x < 0){
    sign = -1;
    x *= -1;
  }
  scs_set_d(sc1, x);
  scs_atanpi(res_scs, sc1);
  scs_get_d(&res.d, res_scs);

  res.d *= sign;

  return res.d;
}
Example #5
0
/*************************************************************
 *************************************************************
 *               ROUNDED  TO NEAREST
 *************************************************************
 *************************************************************/
double log10_rn(double x)
{
  scs_t R, res1;
  scs_t sc_ln2_r10_times_E;
  scs_ptr inv_wi, ti;
 
  db_number nb, nb2, wi, resd;
  int i, E=0;

  nb.d = x;
  /* Filter cases */
  if (nb.i[HI_ENDIAN] < 0x00100000){        /* x < 2^(-1022)    */
    if (((nb.i[HI_ENDIAN] & 0x7fffffff)|nb.i[LO_ENDIAN])==0)
      /* return 1.0/0.0; */                       /* log(+/-0) = -Inf */
	 return NInf.d;
    if (nb.i[HI_ENDIAN] < 0) 
      /* return (x-x)/0; */                       /* log(-x) = Nan    */
	 return NaN.d;

    /* Subnormal number */
    E    -= (SCS_NB_BITS*2); /* keep in mind that x is a subnormal number */ 
    nb.d *=SCS_RADIX_TWO_DOUBLE;  /* make x as normal number     */         
    /* We may just want add 2 to the scs number.index */
    /* may be .... we will see */
  }
  if (nb.i[HI_ENDIAN] >= 0x7ff00000)
    return x+x;                             /* Inf or Nan       */

  /* find n, nb.d such that sqrt(2)/2 < nb.d < sqrt(2) */
  E += (nb.i[HI_ENDIAN]>>20)-1023;
  nb.i[HI_ENDIAN] =  (nb.i[HI_ENDIAN] & 0x000fffff) | 0x3ff00000;
  if (nb.d > SQRT_2){
    nb.d *= 0.5;
    E++;
  }


  /* to normalize nb.d and round to nearest      */
  /* +((2^4 - trunc(sqrt(2)/2) *2^4 )*2 + 1)/2^5 */ 
  nb2.d = nb.d + norm_number.d; 
  i = (nb2.i[HI_ENDIAN] & 0x000fffff);
  i = i >> 16; /* 0<= i <=11 */
  
  wi.d = (11+i)*(double)0.6250e-1;

  /* (1+f-w_i) */
  nb.d -= wi.d; 
  
  /* Table reduction */
  ti     = table_ti_ptr[i]; 
  inv_wi = table_inv_wi_ptr[i];

 
  /* R = (1+f-w_i)/w_i */
  scs_set_d(R, nb.d);
  scs_mul(R, R, inv_wi);
 

  /* sc_ln2_r10_times_E = E*log10(2)  */
  scs_set(sc_ln2_r10_times_E, sc_ln2_r10_ptr);
  
  if (E >= 0){
    scs_mul_ui(sc_ln2_r10_times_E, (unsigned int) E);
  }else{
    scs_mul_ui(sc_ln2_r10_times_E, (unsigned int) -E);
    sc_ln2_r10_times_E->sign = -1;
  }


  /*
   * Polynomial evaluation of log10(1 + R) with an error less than 2^(-130)
   */
  scs_mul(res1, constant_poly_ptr[0], R);
  for(i=1; i<20; i++){
    scs_add(res1, constant_poly_ptr[i], res1);
    scs_mul(res1, res1, R);
  }
  scs_add(res1, res1, ti);
  scs_add(res1, res1, sc_ln2_r10_times_E);  


  scs_get_d(&resd.d, res1);  
  
  return resd.d;
}
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;
    }
}