コード例 #1
0
ファイル: w_powf.c プロジェクト: AgamAgarwal/minix
float
powf(float x, float y)	/* wrapper powf */
{
#ifdef _IEEE_LIBM
	return  __ieee754_powf(x,y);
#else
	float z;
	z=__ieee754_powf(x,y);
	if(_LIB_VERSION == _IEEE_|| isnanf(y)) return z;
	if(isnanf(x)) {
	    if(y==(float)0.0)
	        /* powf(NaN,0.0) */
	        return (float)__kernel_standard((double)x,(double)y,142);
	    else
		return z;
	}
	if(x==(float)0.0){
	    if(y==(float)0.0)
	        /* powf(0.0,0.0) */
	        return (float)__kernel_standard((double)x,(double)y,120);
	    if(finitef(y)&&y<(float)0.0)
	        /* powf(0.0,negative) */
	        return (float)__kernel_standard((double)x,(double)y,123);
	    return z;
	}
	if(!finitef(z)) {
	    if(finitef(x)&&finitef(y)) {
	        if(isnanf(z))
		    /* powf neg**non-int */
	            return (float)__kernel_standard((double)x,(double)y,124);
	        else
		    /* powf overflow */
	            return (float)__kernel_standard((double)x,(double)y,121);
	    }
	}
	if(z==(float)0.0&&finitef(x)&&finitef(y))
	    /* powf underflow */
	    return (float)__kernel_standard((double)x,(double)y,122);
	return z;
#endif
}
コード例 #2
0
ファイル: w_powf.c プロジェクト: nafis-sadik/glibc
/* wrapper powf */
float
__powf (float x, float y)
{
    float z = __ieee754_powf (x, y);
    if (__builtin_expect (!__finitef (z), 0))
    {
        if (_LIB_VERSION != _IEEE_)
        {
            if (__isnanf (x))
            {
                if (y == 0.0f)
                    /* pow(NaN,0.0) */
                    return __kernel_standard_f (x, y, 142);
            }
            else if (__finitef (x) && __finitef (y))
            {
                if (__isnanf (z))
                    /* pow neg**non-int */
                    return __kernel_standard_f (x, y, 124);
                else if (x == 0.0f && y < 0.0f)
                {
                    if (signbit (x) && signbit (z))
                        /* pow(-0.0,negative) */
                        return __kernel_standard_f (x, y, 123);
                    else
                        /* pow(+0.0,negative) */
                        return __kernel_standard_f (x, y, 143);
                }
                else
                    /* pow overflow */
                    return __kernel_standard_f (x, y, 121);
            }
        }
    }
    else if (__builtin_expect (z == 0.0f, 0) && __finitef (x) && __finitef (y)
             && _LIB_VERSION != _IEEE_)
    {
        if (x == 0.0f)
        {
            if (y == 0.0f)
                /* pow(0.0,0.0) */
                return __kernel_standard_f (x, y, 120);
        }
        else
            /* pow underflow */
            return __kernel_standard_f (x, y, 122);
    }

    return z;
}
コード例 #3
0
ファイル: e_gammaf_r.c プロジェクト: RobbenBasten/glibc
static float
gammaf_positive (float x, int *exp2_adj)
{
  int local_signgam;
  if (x < 0.5f)
    {
      *exp2_adj = 0;
      return __ieee754_expf (__ieee754_lgammaf_r (x + 1, &local_signgam)) / x;
    }
  else if (x <= 1.5f)
    {
      *exp2_adj = 0;
      return __ieee754_expf (__ieee754_lgammaf_r (x, &local_signgam));
    }
  else if (x < 2.5f)
    {
      *exp2_adj = 0;
      float x_adj = x - 1;
      return (__ieee754_expf (__ieee754_lgammaf_r (x_adj, &local_signgam))
	      * x_adj);
    }
  else
    {
      float eps = 0;
      float x_eps = 0;
      float x_adj = x;
      float prod = 1;
      if (x < 4.0f)
	{
	  /* Adjust into the range for applying Stirling's
	     approximation.  */
	  float n = __ceilf (4.0f - x);
	  x_adj = math_narrow_eval (x + n);
	  x_eps = (x - (x_adj - n));
	  prod = __gamma_productf (x_adj - n, x_eps, n, &eps);
	}
      /* The result is now gamma (X_ADJ + X_EPS) / (PROD * (1 + EPS)).
	 Compute gamma (X_ADJ + X_EPS) using Stirling's approximation,
	 starting by computing pow (X_ADJ, X_ADJ) with a power of 2
	 factored out.  */
      float exp_adj = -eps;
      float x_adj_int = __roundf (x_adj);
      float x_adj_frac = x_adj - x_adj_int;
      int x_adj_log2;
      float x_adj_mant = __frexpf (x_adj, &x_adj_log2);
      if (x_adj_mant < (float) M_SQRT1_2)
	{
	  x_adj_log2--;
	  x_adj_mant *= 2.0f;
	}
      *exp2_adj = x_adj_log2 * (int) x_adj_int;
      float ret = (__ieee754_powf (x_adj_mant, x_adj)
		   * __ieee754_exp2f (x_adj_log2 * x_adj_frac)
		   * __ieee754_expf (-x_adj)
		   * __ieee754_sqrtf (2 * (float) M_PI / x_adj)
		   / prod);
      exp_adj += x_eps * __ieee754_logf (x_adj);
      float bsum = gamma_coeff[NCOEFF - 1];
      float x_adj2 = x_adj * x_adj;
      for (size_t i = 1; i <= NCOEFF - 1; i++)
	bsum = bsum / x_adj2 + gamma_coeff[NCOEFF - 1 - i];
      exp_adj += bsum / x_adj;
      return ret + ret * __expm1f (exp_adj);
    }
}