Ejemplo n.º 1
0
Archivo: scalbf.c Proyecto: 5kg/osv
float scalbf(float x, float fn)
{
	if (isnan(x) || isnan(fn)) return x*fn;
	if (!isfinite(fn)) {
		if (fn > 0.0f)
			return x*fn;
		else
			return x/(-fn);
	}
	if (rintf(fn) != fn) return (fn-fn)/(fn-fn);
	if ( fn > 65000.0f) return scalbnf(x, 65000);
	if (-fn > 65000.0f) return scalbnf(x,-65000);
	return scalbnf(x,(int)fn);
}
Ejemplo n.º 2
0
void testValues() {
    f = 2;
    float result;
    
    result = scalbnf(5.0f, 3);
    // assert result = 5.0 * \pow(FLT_RADIX, 3.0);
    result = scalbnf(1.2f, 8);
    // assert result = 1.2 * \pow(FLT_RADIX, 8.3);
    result = scalbnf(FLT_MAX, INT_MAX);
    // assert result == HUGE_VALF;
    // assert (math_errhandling & MATH_ERRNO) ==> (errno == ERANGE);
    
    //@ assert f == 2;
    //@ assert vacuous: \false;
}
Ejemplo n.º 3
0
float ldexpf(float value, int exp)
{
	if(!finitef(value)||value==(float)0.0) return value;
	value = scalbnf(value,exp);
	if(!finitef(value)||value==(float)0.0) errno = ERANGE;
	return value;
}
Ejemplo n.º 4
0
void test_scalbn()
{
    static_assert((std::is_same<decltype(scalbn((double)0, (int)0)), double>::value), "");
    static_assert((std::is_same<decltype(scalbnf(0, (int)0)), float>::value), "");
    static_assert((std::is_same<decltype(scalbnl(0, (int)0)), long double>::value), "");
    assert(scalbn(1, 1) == 2);
}
Ejemplo n.º 5
0
_M_INL	float __ieee754_scalbf(float x, float fn)
#endif
{
#ifdef _SCALB_INT
	return scalbnf(x,fn);
#else
	if (isnanf(x)||isnanf(fn)) return x*fn;
	if (!finitef(fn)) {
	    if(fn>(float)0.0) return x*fn;
	    else       return x/(-fn);
	}
	if (rintf(fn)!=fn) return (fn-fn)/(fn-fn);
	if ( fn > (float)65000.0) return scalbnf(x, 65000);
	if (-fn > (float)65000.0) return scalbnf(x,-65000);
	return scalbnf(x,(int)fn);
#endif
}
Ejemplo n.º 6
0
float scalblnf(float x, long n)
{
	if (n > INT_MAX)
		n = INT_MAX;
	else if (n < INT_MIN)
		n = INT_MIN;
	return scalbnf(x, n);
}
Ejemplo n.º 7
0
/* This is a portable implementation of nextafterf that is intended to be
   independent of the floating point format or its in memory representation.
   This implementation works correctly with denormalized values.  */
float
nextafterf(float x, float y)
{
  /* This variable is marked volatile to avoid excess precision problems
     on some platforms, including IA-32.  */
  volatile float delta;
  float absx, denorm_min;

  if (isnan(x) || isnan(y))
    return x + y;
  if (x == y)
    return x;
  if (!isfinite (x))
    return x > 0 ? __FLT_MAX__ : - __FLT_MAX__;

  /* absx = fabsf (x);  */
  absx = (x < 0.0) ? -x : x;

  /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals.  */
  if (__FLT_DENORM_MIN__ == 0.0f)
    denorm_min = __FLT_MIN__;
  else
    denorm_min = __FLT_DENORM_MIN__;

  if (absx < __FLT_MIN__)
    delta = denorm_min;
  else
    {
      float frac;
      int exp;

      /* Discard the fraction from x.  */
      frac = frexpf (absx, &exp);
      delta = scalbnf (0.5f, exp);

      /* Scale x by the epsilon of the representation.  By rights we should
	 have been able to combine this with scalbnf, but some targets don't
	 get that correct with denormals.  */
      delta *= __FLT_EPSILON__;

      /* If we're going to be reducing the absolute value of X, and doing so
	 would reduce the exponent of X, then the delta to be applied is
	 one exponent smaller.  */
      if (frac == 0.5f && (y < x) == (x > 0))
	delta *= 0.5f;

      /* If that underflows to zero, then we're back to the minimum.  */
      if (delta == 0.0f)
	delta = denorm_min;
    }

  if (y < x)
    delta = -delta;

  return x + delta;
}
Ejemplo n.º 8
0
/*++
Function:
    scalbnf

See MSDN.
--*/
PALIMPORT float __cdecl PAL_scalbnf(float x, int n)
{
    float ret;
    PERF_ENTRY(scalbnf);
    ENTRY("scalbnf (x=%f, n=%d)\n", x, n);

    ret = scalbnf(x, n);

    LOGEXIT("scalbnf returns double %f\n", ret);
    PERF_EXIT(scalbnf);
    return ret;
}
Ejemplo n.º 9
0
float expf(float x)
{
	float_t hi, lo, c, xx, y;
	int k, sign;
	uint32_t hx;

	GET_FLOAT_WORD(hx, x);
	sign = hx >> 31;   /* sign bit of x */
	hx &= 0x7fffffff;  /* high word of |x| */

	/* special cases */
	if (hx >= 0x42aeac50) {  /* if |x| >= -87.33655f or NaN */
		if (hx >= 0x42b17218 && !sign) {  /* x >= 88.722839f */
			/* overflow */
			x *= 0x1p127f;
			return x;
		}
		if (sign) {
			/* underflow */
			FORCE_EVAL(-0x1p-149f/x);
			if (hx >= 0x42cff1b5)  /* x <= -103.972084f */
				return 0;
		}
	}

	/* argument reduction */
	if (hx > 0x3eb17218) {  /* if |x| > 0.5 ln2 */
		if (hx > 0x3f851592)  /* if |x| > 1.5 ln2 */
			k = invln2*x + half[sign];
		else
			k = 1 - sign - sign;
		hi = x - k*ln2hi;  /* k*ln2hi is exact here */
		lo = k*ln2lo;
		x = hi - lo;
	} else if (hx > 0x39000000) {  /* |x| > 2**-14 */
		k = 0;
		hi = x;
		lo = 0;
	} else {
		/* raise inexact */
		FORCE_EVAL(0x1p127f + x);
		return 1 + x;
	}

	/* x is now in primary range */
	xx = x*x;
	c = x - xx*(P1+xx*P2);
	y = 1 + (x*c/(2-c) - lo + hi);
	if (k == 0)
		return y;
	return scalbnf(y, k);
}
Ejemplo n.º 10
0
float
scalblnf (float x, long n)
{
	int in;

	in = (int)n;
	if (in != n) {
		if (n > 0)
			in = INT_MAX;
		else
			in = INT_MIN;
	}
	return (scalbnf(x, in));
}
Ejemplo n.º 11
0
int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec,
		const s32_t *ipio2)
{
	s32_t jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih;
	float z, fw, f[20], fq[20], q[20];

	jk = init_jk[prec];
	jp = jk;

	jx = nx - 1;
	jv = (e0 - 3) / 8;
	if (jv < 0)
		jv = 0;
	q0 = e0 - 8 * (jv + 1);

	j = jv - jx;
	m = jx + jk;
	for (i = 0; i <= m; i++, j++)
		f[i] = (j < 0) ? zero : (float) ipio2[j];

	for (i = 0; i <= jk; i++)
	{
		for (j = 0, fw = 0.0; j <= jx; j++)
			fw += x[j] * f[jx + i - j];
		q[i] = fw;
	}

	jz = jk;
	recompute:
	for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--)
	{
		fw = (float) ((s32_t)(twon8 * z));
		iq[i] = (s32_t)(z - two8 * fw);
		z = q[j - 1] + fw;
	}

	z = scalbnf(z, q0);
	z -= (float) 8.0 * floorf(z * (float) 0.125);
	n = (s32_t) z;
	z -= (float) n;
	ih = 0;
	if (q0 > 0)
	{
		i = (iq[jz - 1] >> (8 - q0));
		n += i;
		iq[jz - 1] -= i << (8 - q0);
		ih = iq[jz - 1] >> (7 - q0);
	}
Ejemplo n.º 12
0
int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const __int32_t *ipio2)
{
    __int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
    float z,fw,f[20],fq[20],q[20];

    /* initialize jk*/
    jk = init_jk[prec];
    jp = jk;

    /* determine jx,jv,q0, note that 3>q0 */
    jx =  nx-1;
    jv = (e0-3)/8;
    if(jv<0) jv=0;
    q0 =  e0-8*(jv+1);

    /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
    j = jv-jx;
    m = jx+jk;
    for(i=0; i<=m; i++,j++) f[i] = (j<0)? zero : (float) ipio2[j];

    /* compute q[0],q[1],...q[jk] */
    for (i=0; i<=jk; i++) {
        for(j=0,fw=0.0; j<=jx; j++) fw += x[j]*f[jx+i-j];
        q[i] = fw;
    }

    jz = jk;
recompute:
    /* distill q[] into iq[] reversingly */
    for(i=0,j=jz,z=q[jz]; j>0; i++,j--) {
        fw    =  (float)((__int32_t)(twon8* z));
        iq[i] =  (__int32_t)(z-two8*fw);
        z     =  q[j-1]+fw;
    }

    /* compute n */
    z  = scalbnf(z,(int)q0);	/* actual value of z */
    z -= (float)8.0*floorf(z*(float)0.125);	/* trim off integer >= 8 */
    n  = (__int32_t) z;
    z -= (float)n;
    ih = 0;
    if(q0>0) {	/* need iq[jz-1] to determine n */
        i  = (iq[jz-1]>>(8-q0));
        n += i;
        iq[jz-1] -= i<<(8-q0);
        ih = iq[jz-1]>>(7-q0);
    }
Ejemplo n.º 13
0
float nextafterf(const float x, const float y)
{
    int origexp, newexp;
#ifdef isnan
    if (isnan(x) || isnan(y))
        return x + y;
#endif
    if (x == y)
        return x;
    if (x == 0.0f)
        return y > 0.0 ? FLT_MIN : -FLT_MIN;
    frexpf(x, &origexp);
    if (x >= 0.0f) {
        if (y > x) {
            if (x < FLT_MIN)
                return FLT_MIN;
            return x + scalbnf(FLT_EPSILON, origexp - 1);
        } else if (x > FLT_MIN) {
            float temp = x - scalbnf(FLT_EPSILON, origexp - 1);
            frexpf(temp, &newexp);
            if (newexp == origexp)
                return temp;
            return x - scalbnf(FLT_EPSILON, origexp - 2);
        } else
            return 0.0f;
    } else {
        if (y < x) {
            if (x > -FLT_MIN)
                return -FLT_MIN;
            return x - scalbnf(FLT_EPSILON, origexp - 1);
        } else if (x < -FLT_MIN) {
            float temp = x + scalbnf(FLT_EPSILON, origexp - 1);
            frexpf(temp, &newexp);
            if (newexp == origexp)
                return temp;
            return x + scalbnf(FLT_EPSILON, origexp - 2);
        } else
            return 0.0f;
    }
}
Ejemplo n.º 14
0
float
scalblnf (float x, long n)
{

	return (scalbnf(x, (int)n));
}
Ejemplo n.º 15
0
float fmodf ( float x, float y )
{
    int			  iclx,icly;                           /* classify results of x,y */
    int32_t		  iscx,iscy,idiff;                     /* logb values and difference */
    int			  i;                                   /* loop variable */
    float        absy,x1,y1,z;                        /* local floating-point variables */
    float        rslt;
    fenv_t        OldEnv;
    hexdouble     OldEnvironment;
    int           newexc;
    
    FEGETENVD( OldEnvironment.d );
    FESETENVD( 0.0 );
	  __NOOP;
	  __NOOP;

    OldEnv = OldEnvironment.i.lo;
    
    iclx = __fpclassifyf(x);
    icly = __fpclassifyf(y);
    if (likely((iclx & icly) >= FP_NORMAL))    {       /* x,y both nonzero finite case */
         x1 = __FABSF(x);                              /* work with absolute values */
         absy = __FABSF(y);
         if (absy > x1) {
              rslt = x;                               /* trivial case */
                  goto ret;
            }
         else {                                       /* nontrivial case requires reduction */
              iscx = (int32_t) logbf(x1);             /* get binary exponents of |x| and |y| */
              iscy = (int32_t) logbf(absy);
              idiff = iscx - iscy;                    /* exponent difference */
              if (idiff != 0) {                       /* exponent of x1 > exponent of y1 */
                   y1 = scalbnf(absy,-iscy);            /* scale |y| to unit binade */
                   x1 = scalbnf(x1,-iscx);              /* ditto for |x| */
                   for (i = idiff; i != 0; i--) {     /* begin remainder loop */
                        if ((z = x1 - y1) >= 0) {     /* nonzero remainder step result */
                            x1 = z;                   /*   update remainder (x1) */
                        }
                        x1 += x1;                     /* shift (by doubling) remainder */
                   }                                  /* end of remainder loop */
                   x1 = scalbnf(x1,iscy);               /* scale result to binade of |y| */
              }                                       /* remainder exponent >= exponent of y */
              if (x1 >= absy) {                       /* last step to obtain modulus */
                   x1 -= absy;
              }    
         }                                            /* x1 is |result| */
         if (x < 0.0)
              x1 = -x1;                               /* modulus if x is negative */
         rslt = x1;
         goto ret;
    }                                                 /* end of x,y both nonzero finite case */
    else if ((iclx <= FP_QNAN) || (icly <= FP_QNAN)) {
         rslt = x+y;                                  /* at least one NaN operand */
         goto ret;
      }
    else if ((iclx == FP_INFINITE)||(icly == FP_ZERO)) {    /* invalid result */
         rslt = nanf(REM_NAN);
            OldEnvironment.i.lo |= SET_INVALID;
            FESETENVD_GRP ( OldEnvironment.d );
         goto ret;
    }
    else                                              /* trivial cases (finite MOD infinite   */
         rslt = x;                                    /*  or  zero REM nonzero) with *quo = 0 */
  ret:
    FEGETENVD_GRP (OldEnvironment.d );
    newexc = OldEnvironment.i.lo & FE_ALL_EXCEPT;
    OldEnvironment.i.lo = OldEnv;
    if ((newexc & FE_INVALID) != 0)
          OldEnvironment.i.lo |= SET_INVALID;
    OldEnvironment.i.lo |=  newexc & ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW );
    FESETENVD_GRP (OldEnvironment.d );
    return rslt;
}
Ejemplo n.º 16
0
float remquof ( float x, float y, int *quo)
{
      int			iclx,icly;                        /* classify results of x,y */
      int32_t		iquo;                             /* low 32 bits of integral quotient */
      int32_t		iscx, iscy, idiff;                /* logb values and difference */
      int			i;                                /* loop variable */
      float        absy,x1,y1,z;                     /* local floating-point variables */
      float        rslt;
      fenv_t        OldEnv;
      hexdouble     OldEnvironment;
      int           newexc;
    
      FEGETENVD ( OldEnvironment.d );
      FESETENVD ( 0.0 );
	  __NOOP;
	  __NOOP;

      OldEnv = OldEnvironment.i.lo;
      
      *quo = 0;                                       /* initialize quotient result */
      iclx = __fpclassifyf(x);
      icly = __fpclassifyf(y);
      if (likely((iclx & icly) >= FP_NORMAL))    {     /* x,y both nonzero finite case */
         x1 = __FABSF(x);                              /* work with absolute values */
         absy = __FABSF(y);
         iquo = 0;                                    /* zero local quotient */
         iscx = (int32_t) logbf(x1);                  /* get binary exponents */
         iscy = (int32_t) logbf(absy);
         idiff = iscx - iscy;                         /* exponent difference */
         if (idiff >= 0) {                            /* exponent of x1 >= exponent of y1 */
              if (idiff != 0) {                       /* exponent of x1 > exponent of y1 */
                   y1 = scalbnf(absy,-iscy);            /* scale |y| to unit binade */
                   x1 = scalbnf(x1,-iscx);              /* ditto for |x| */
                   for (i = idiff; i != 0; i--) {     /* begin remainder loop */
                        if ((z = x1 - y1) >= 0) {     /* nonzero remainder step result */
                            x1 = z;                   /* update remainder (x1) */
                            iquo += 1;                /* increment quotient */
                        }
                        iquo += iquo;                 /* shift quotient left one bit */
                        x1 += x1;                     /* shift (double) remainder */
                   }                                  /* end of remainder loop */
                   x1 = scalbnf(x1,iscy);               /* scale remainder to binade of |y| */
              }                                       /* remainder has exponent <= exponent of y */
              if (x1 >= absy) {                       /* last remainder step */
                   x1 -= absy;
                   iquo +=1;
              }                                       /* end of last remainder step */
         }                                            /* remainder (x1) has smaller exponent than y */
         if (likely( x1 < HugeFHalved.fval ))
            z = x1 + x1;                              /* double remainder, without overflow */
         else
            z = HugeF.fval;
         if ((z > absy) || ((z == absy) && ((iquo & 1) != 0))) {
              x1 -= absy;                             /* final remainder correction */
              iquo += 1;
         }
         if (x < 0.0)
              x1 = -x1;                               /* remainder if x is negative */
         iquo &= 0x0000007f;                          /* retain low 7 bits of integer quotient */
         if ((signbit(x) ^ signbit(y)) != 0)    /* take care of sign of quotient */
              iquo = -iquo;
         *quo = iquo;                                 /* deliver quotient result */
         rslt = x1;
         goto ret;
    }                                                 /* end of x,y both nonzero finite case */
    else if ((iclx <= FP_QNAN) || (icly <= FP_QNAN)) {
         rslt = x+y;                                  /* at least one NaN operand */
         goto ret;
    }
    else if ((iclx == FP_INFINITE)||(icly == FP_ZERO)) {    /* invalid result */
         rslt = nanf(REM_NAN);
            OldEnvironment.i.lo |= SET_INVALID;
            FESETENVD_GRP( OldEnvironment.d );
         goto ret;
    }
    else                                              /* trivial cases (finite REM infinite   */
         rslt = x;                                    /*  or  zero REM nonzero) with *quo = 0 */
  ret:
      FEGETENVD_GRP( OldEnvironment.d );
      newexc = OldEnvironment.i.lo & FE_ALL_EXCEPT;
      OldEnvironment.i.lo = OldEnv;
      if ((newexc & FE_INVALID) != 0)
            OldEnvironment.i.lo |= SET_INVALID;
      OldEnvironment.i.lo |=  newexc & ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW );
      FESETENVD_GRP( OldEnvironment.d );
      return rslt;
}
Ejemplo n.º 17
0
/*
=============
R_SetupGL
=============
*/
void R_SetupGL (void)
{
	float	screenaspect;
	float	yfov;
	int		i;
	extern	int glwidth, glheight;
	int		x, x2, y2, y, w, h;

	//
	// set up viewpoint
	//
	glMatrixMode(GL_PROJECTION);
    glLoadIdentity ();
	x = r_refdef.vrect.x * glwidth/vid.width;
	x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/vid.width;
	y = (vid.height-r_refdef.vrect.y) * glheight/vid.height;
	y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/vid.height;

	// fudge around because of frac screen scale
	if (x > 0)
		x--;
	if (x2 < glwidth)
		x2++;
	if (y2 < 0)
		y2--;
	if (y < glheight)
		y++;

	w = x2 - x;
	h = y - y2;

	if (envmap)
	{
		x = y2 = 0;
		w = h = 256;
	}

	glViewport (glx + x, gly + y2, w, h);
    screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height;
//	yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI;
    MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  4096);

	if (mirror)
	{
		if (mirror_plane->normal[2])
			glScalef (1, -1, 1);
		else
			glScalef (-1, 1, 1);
		glCullFace(GL_BACK);
	}
	else
		glCullFace(GL_FRONT);

	glMatrixMode(GL_MODELVIEW);

#ifdef DO_OWN_MATRIX_MATH

	float mv[16];
    setIdentityM(mv, 0);

    rotateM(mv, -90,  1, 0, 0);	    // put Z going up
    rotateM(mv, 90,  0, 0, 1);	    // put Z going up
    rotateM(mv, -r_refdef.viewangles[2],  1, 0, 0);
    rotateM(mv, -r_refdef.viewangles[0],  0, 1, 0);
    rotateM(mv, -r_refdef.viewangles[1],  0, 0, 1);
    translateM(mv, 0, -r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);

    glLoadMatrixf(mv);

    memcpy(r_world_matrix, mv, sizeof(r_world_matrix));

#else
    glLoadIdentity ();

    glRotatef (-90,  1, 0, 0);	    // put Z going up
    glRotatef (90,  0, 0, 1);	    // put Z going up
    glRotatef (-r_refdef.viewangles[2],  1, 0, 0);
    glRotatef (-r_refdef.viewangles[0],  0, 1, 0);
    glRotatef (-r_refdef.viewangles[1],  0, 0, 1);
    glTranslatef (-r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);

#ifdef USE_OPENGLES

    static qboolean initialized;
    static qboolean haveGL_OES_matrix_get;
    static qboolean haveGL_OES_query_matrix;

#if 0
    if (! initialized) {
        const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
        haveGL_OES_matrix_get =
            strstr(extensions, "GL_OES_matrix_get") != NULL;
        haveGL_OES_query_matrix =
            strstr(extensions, "GL_OES_query_matrix") != NULL;
        initialized = true;
    }
    if (haveGL_OES_query_matrix) {
        GLfixed mantissa[16];
        GLint exponent[16];
        glQueryMatrixxOES( mantissa, exponent );
        for(int i = 0; i < 16; i++) {
            r_world_matrix[i] = scalbnf(mantissa[i], exponent[i]-16);
        }
    }
    else if (haveGL_OES_matrix_get) {
        glGetIntegerv (MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES,
                (GLint*) r_world_matrix);
    }
    else
#endif
    	{
        // No way to get the world matix, set to identity
        memset(r_world_matrix, 0, sizeof(r_world_matrix));
        for(i = 0; i < 16; i += 5) {
            r_world_matrix[i] = 1.0f;
        }
    }
#else
	glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
#endif
#endif // DO_OWN_MATRIX_MATH
	//
	// set drawing parms
	//
	if (gl_cull.value)
		glEnable(GL_CULL_FACE);
	else
		glDisable(GL_CULL_FACE);

	glDisable(GL_BLEND);
	glDisable(GL_ALPHA_TEST);
	glEnable(GL_DEPTH_TEST);
}
Ejemplo n.º 18
0
float
ldexpf(float x, int n) {
	return (scalbnf(x, n));
}
Ejemplo n.º 19
0
float _EWL_MATH_CDECL
scalblnf(float x, long int y)
{
	return scalbnf(x, y);
}
Ejemplo n.º 20
0
sl_def(do_test, void)
{
#define x values[p].d
#define xf values[p].f
#define y values[p+1].d
#define yf values[p+1].f
#define n values[p+2].i
#define nl values[p+2].l

#define call1(F)                                 \
  values[p].desc = #F;                           \
  values[p].d = F(x);                            \
  ++p;                                           \
  values[p].desc = #F "f";                       \
  values[p].f = F ## f (xf);                     \
  ++p


#define call1i(F)				\
  values[p].desc = #F;				\
  values[p].i = F(x);                           \
  ++p

#define call2(F)                                  \
  values[p].desc = #F;                            \
  values[p].d = F(x, y);                          \
  p += 2;                                         \
  values[p].desc = #F "f";                        \
  values[p].f = F ## f (xf, yf);                  \
  p += 2

#define call2i(F)                                 \
  values[p].desc = #F;                            \
  values[p].i = F(x, y);                          \
  p += 2;                                         \
  values[p].desc = #F "f";                        \
  values[p].i = F(xf, yf);                        \
  p += 2

  /* classify */
  call1i(fpclassify);
  call1i(signbit);
  call1i(isfinite);
  call1i(isnormal);
  call1i(isnan);
  call1i(isinf);

  /* trig */
  call1(acos);
  call1(asin);
  call1(atan);
  call2(atan2);
  call1(cos);
  call1(sin);
  call1(tan);

  /* hyperbolic */
  call1(acosh);
  call1(asinh);
  call1(atanh);
  call1(cosh);
  call1(sinh);
  call1(tanh);

  /* exp/log */
  call1(exp);
  call1(exp2);
  call1(expm1);

  values[p].desc = "frexp";
  values[p].d = frexp(x, &values[p+1].i);
  p += 2;

  values[p].desc = "frexpf";
  values[p].f = frexpf(xf, &values[p+1].i);
  p += 2;

  values[p].desc = "ilogb";
  values[p].i = ilogb(x); p++;
  values[p].desc = "ilogbf";
  values[p].i = ilogbf(xf); p++;

  values[p].desc = "ldexp";
  values[p].d = ldexp(x, n); p+=3;
  values[p].desc = "ldexpf";
  values[p].f = ldexpf(xf, n); p+=3;

  call1(log);
  call1(log10);
  call1(log1p);
  call1(log2);
  call1(logb);

  values[p].desc = "modf";
  values[p].d = modf(x, &y); 
  p += 2;

  values[p].desc = "modff";
  values[p].f = modff(xf, &yf);
  p += 2;

  values[p].desc = "scalbn";
  values[p].d = scalbn(x, n); p+=3;
  values[p].desc = "scalbnf";
  values[p].f = scalbnf(xf, n); p+=3;

  values[p].desc = "scalbln";
  values[p].d = scalbln(x, nl); p+=3;
  values[p].desc = "scalblnf";
  values[p].f = scalblnf(xf, nl); p+=3;

  /* power/abs */

  call1(cbrt);
  call1(fabs);
  call2(hypot);
  call2(pow);
  call1(sqrt);

  /* error/gamma */
  call1(erf);
  call1(erfc);
  call1(lgamma);
  call1(tgamma); 
  call1(ceil);
  call1(floor);
  call1(nearbyint);
  call1(rint);
  call1(lrint);

  values[p].desc = "lrint";
  values[p].l = lrint(x); p++;
  values[p].desc = "lrintf";
  values[p].l = lrintf(xf); p++;
  values[p].desc = "llrint";
  values[p].ll = llrint(x); p++;
  values[p].desc = "llrintf";
  values[p].ll = llrintf(xf); p++;

  call1(round);

  values[p].desc = "lround";
  values[p].l = lround(x); p++;
  values[p].desc = "lroundf";
  values[p].l = lroundf(xf); p++;
  values[p].desc = "llround";
  values[p].ll = llround(x); p++;
  values[p].desc = "llroundf";
  values[p].ll = llroundf(xf); p++;

  call1(trunc);

  /* rem/mod */
  call2(fmod);
  call2(remainder);

  values[p].desc = "remquo";
  values[p].d = remquo(x, y, &values[p+1].i); p+=2;
  values[p].desc = "remquof";
  values[p].f = remquof(xf, yf, &values[p+1].i); p+=2;

  call2(copysign);

  /* nan */

  values[p].desc = "nan";
  values[p].d = nan(""); ++p;
  values[p].desc = "nanf";
  values[p].f = nanf(""); ++p;

  call2(nextafter);

  /* min/max/dim */
  call2(fdim);
  call2(fmax);
  call2(fmin);
  values[p].desc = "fma";
  values[p].d = fma(x, y, values[p+2].d); p+=3;
  values[p].desc = "fmaf";
  values[p].d = fmaf(xf, yf, values[p+2].f); p+=3;

  /* comp */
  call2i(isgreater);
  call2i(isgreaterequal);
  call2i(isless);
  call2i(islessequal);
  call2i(islessgreater);
  call2i(isunordered);

#undef x
#undef xf
#undef y
#undef n
}
Ejemplo n.º 21
0
static int testf(float float_x, long double long_double_x, /*float complex float_complex_x,*/ int int_x, long long_x)
{
int r = 0;
r += acosf(float_x);
r += acoshf(float_x);
r += asinf(float_x);
r += asinhf(float_x);
r += atan2f(float_x, float_x);
r += atanf(float_x);
r += atanhf(float_x);
/*r += cargf(float_complex_x); - will fight with complex numbers later */
r += cbrtf(float_x);
r += ceilf(float_x);
r += copysignf(float_x, float_x);
r += cosf(float_x);
r += coshf(float_x);
r += erfcf(float_x);
r += erff(float_x);
r += exp2f(float_x);
r += expf(float_x);
r += expm1f(float_x);
r += fabsf(float_x);
r += fdimf(float_x, float_x);
r += floorf(float_x);
r += fmaf(float_x, float_x, float_x);
r += fmaxf(float_x, float_x);
r += fminf(float_x, float_x);
r += fmodf(float_x, float_x);
r += frexpf(float_x, &int_x);
r += gammaf(float_x);
r += hypotf(float_x, float_x);
r += ilogbf(float_x);
r += ldexpf(float_x, int_x);
r += lgammaf(float_x);
r += llrintf(float_x);
r += llroundf(float_x);
r += log10f(float_x);
r += log1pf(float_x);
r += log2f(float_x);
r += logbf(float_x);
r += logf(float_x);
r += lrintf(float_x);
r += lroundf(float_x);
r += modff(float_x, &float_x);
r += nearbyintf(float_x);
r += nexttowardf(float_x, long_double_x);
r += powf(float_x, float_x);
r += remainderf(float_x, float_x);
r += remquof(float_x, float_x, &int_x);
r += rintf(float_x);
r += roundf(float_x);
#ifdef __UCLIBC_SUSV3_LEGACY__
r += scalbf(float_x, float_x);
#endif
r += scalblnf(float_x, long_x);
r += scalbnf(float_x, int_x);
r += significandf(float_x);
r += sinf(float_x);
r += sinhf(float_x);
r += sqrtf(float_x);
r += tanf(float_x);
r += tanhf(float_x);
r += tgammaf(float_x);
r += truncf(float_x);
return r;
}
Ejemplo n.º 22
0
void
domathf (void)
{
#ifndef NO_FLOAT
  float f1;
  float f2;

  int i1;

  f1 = acosf(0.0);
  fprintf( stdout, "acosf          : %f\n", f1);

  f1 = acoshf(0.0);
  fprintf( stdout, "acoshf         : %f\n", f1);

  f1 = asinf(1.0);
  fprintf( stdout, "asinf          : %f\n", f1);

  f1 = asinhf(1.0);
  fprintf( stdout, "asinhf         : %f\n", f1);

  f1 = atanf(M_PI_4);
  fprintf( stdout, "atanf          : %f\n", f1);

  f1 = atan2f(2.3, 2.3);
  fprintf( stdout, "atan2f         : %f\n", f1);

  f1 = atanhf(1.0);
  fprintf( stdout, "atanhf         : %f\n", f1);

  f1 = cbrtf(27.0);
  fprintf( stdout, "cbrtf          : %f\n", f1);

  f1 = ceilf(3.5);
  fprintf( stdout, "ceilf          : %f\n", f1);

  f1 = copysignf(3.5, -2.5);
  fprintf( stdout, "copysignf      : %f\n", f1);

  f1 = cosf(M_PI_2);
  fprintf( stdout, "cosf           : %f\n", f1);

  f1 = coshf(M_PI_2);
  fprintf( stdout, "coshf          : %f\n", f1);

  f1 = erff(42.0);
  fprintf( stdout, "erff           : %f\n", f1);

  f1 = erfcf(42.0);
  fprintf( stdout, "erfcf          : %f\n", f1);

  f1 = expf(0.42);
  fprintf( stdout, "expf           : %f\n", f1);

  f1 = exp2f(0.42);
  fprintf( stdout, "exp2f          : %f\n", f1);

  f1 = expm1f(0.00042);
  fprintf( stdout, "expm1f         : %f\n", f1);

  f1 = fabsf(-1.123);
  fprintf( stdout, "fabsf          : %f\n", f1);

  f1 = fdimf(1.123, 2.123);
  fprintf( stdout, "fdimf          : %f\n", f1);

  f1 = floorf(0.5);
  fprintf( stdout, "floorf         : %f\n", f1);
  f1 = floorf(-0.5);
  fprintf( stdout, "floorf         : %f\n", f1);

  f1 = fmaf(2.1, 2.2, 3.01);
  fprintf( stdout, "fmaf           : %f\n", f1);

  f1 = fmaxf(-0.42, 0.42);
  fprintf( stdout, "fmaxf          : %f\n", f1);

  f1 = fminf(-0.42, 0.42);
  fprintf( stdout, "fminf          : %f\n", f1);

  f1 = fmodf(42.0, 3.0);
  fprintf( stdout, "fmodf          : %f\n", f1);

  /* no type-specific variant */
  i1 = fpclassify(1.0);
  fprintf( stdout, "fpclassify     : %d\n", i1);

  f1 = frexpf(42.0, &i1);
  fprintf( stdout, "frexpf         : %f\n", f1);

  f1 = hypotf(42.0, 42.0);
  fprintf( stdout, "hypotf         : %f\n", f1);

  i1 = ilogbf(42.0);
  fprintf( stdout, "ilogbf         : %d\n", i1);

  /* no type-specific variant */
  i1 = isfinite(3.0);
  fprintf( stdout, "isfinite       : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreater(3.0, 3.1);
  fprintf( stdout, "isgreater      : %d\n", i1);

  /* no type-specific variant */
  i1 = isgreaterequal(3.0, 3.1);
  fprintf( stdout, "isgreaterequal : %d\n", i1);

  /* no type-specific variant */
  i1 = isinf(3.0);
  fprintf( stdout, "isinf          : %d\n", i1);

  /* no type-specific variant */
  i1 = isless(3.0, 3.1);
  fprintf( stdout, "isless         : %d\n", i1);

  /* no type-specific variant */
  i1 = islessequal(3.0, 3.1);
  fprintf( stdout, "islessequal    : %d\n", i1);

  /* no type-specific variant */
  i1 = islessgreater(3.0, 3.1);
  fprintf( stdout, "islessgreater  : %d\n", i1);

  /* no type-specific variant */
  i1 = isnan(0.0);
  fprintf( stdout, "isnan          : %d\n", i1);

  /* no type-specific variant */
  i1 = isnormal(3.0);
  fprintf( stdout, "isnormal       : %d\n", i1);

  /* no type-specific variant */
  f1 = isunordered(1.0, 2.0);
  fprintf( stdout, "isunordered    : %d\n", i1);

  f1 = j0f(1.2);
  fprintf( stdout, "j0f            : %f\n", f1);

  f1 = j1f(1.2);
  fprintf( stdout, "j1f            : %f\n", f1);

  f1 = jnf(2,1.2);
  fprintf( stdout, "jnf            : %f\n", f1);

  f1 = ldexpf(1.2,3);
  fprintf( stdout, "ldexpf         : %f\n", f1);

  f1 = lgammaf(42.0);
  fprintf( stdout, "lgammaf        : %f\n", f1);

  f1 = llrintf(-0.5);
  fprintf( stdout, "llrintf        : %f\n", f1);
  f1 = llrintf(0.5);
  fprintf( stdout, "llrintf        : %f\n", f1);

  f1 = llroundf(-0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);
  f1 = llroundf(0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);

  f1 = logf(42.0);
  fprintf( stdout, "logf           : %f\n", f1);

  f1 = log10f(42.0);
  fprintf( stdout, "log10f         : %f\n", f1);

  f1 = log1pf(42.0);
  fprintf( stdout, "log1pf         : %f\n", f1);

  f1 = log2f(42.0);
  fprintf( stdout, "log2f          : %f\n", f1);

  f1 = logbf(42.0);
  fprintf( stdout, "logbf          : %f\n", f1);

  f1 = lrintf(-0.5);
  fprintf( stdout, "lrintf         : %f\n", f1);
  f1 = lrintf(0.5);
  fprintf( stdout, "lrintf         : %f\n", f1);

  f1 = lroundf(-0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);
  f1 = lroundf(0.5);
  fprintf( stdout, "lroundf        : %f\n", f1);

  f1 = modff(42.0,&f2);
  fprintf( stdout, "lmodff         : %f\n", f1);

  f1 = nanf("");
  fprintf( stdout, "nanf           : %f\n", f1);

  f1 = nearbyintf(1.5);
  fprintf( stdout, "nearbyintf     : %f\n", f1);

  f1 = nextafterf(1.5,2.0);
  fprintf( stdout, "nextafterf     : %f\n", f1);

  f1 = powf(3.01, 2.0);
  fprintf( stdout, "powf           : %f\n", f1);

  f1 = remainderf(3.01,2.0);
  fprintf( stdout, "remainderf     : %f\n", f1);

  f1 = remquof(29.0,3.0,&i1);
  fprintf( stdout, "remquof        : %f\n", f1);

  f1 = rintf(0.5);
  fprintf( stdout, "rintf          : %f\n", f1);
  f1 = rintf(-0.5);
  fprintf( stdout, "rintf          : %f\n", f1);

  f1 = roundf(0.5);
  fprintf( stdout, "roundf         : %f\n", f1);
  f1 = roundf(-0.5);
  fprintf( stdout, "roundf         : %f\n", f1);

  f1 = scalblnf(1.2,3);
  fprintf( stdout, "scalblnf       : %f\n", f1);

  f1 = scalbnf(1.2,3);
  fprintf( stdout, "scalbnf        : %f\n", f1);

  /* no type-specific variant */
  i1 = signbit(1.0);
  fprintf( stdout, "signbit        : %i\n", i1);

  f1 = sinf(M_PI_4);
  fprintf( stdout, "sinf           : %f\n", f1);

  f1 = sinhf(M_PI_4);
  fprintf( stdout, "sinhf          : %f\n", f1);

  f1 = sqrtf(9.0);
  fprintf( stdout, "sqrtf          : %f\n", f1);

  f1 = tanf(M_PI_4);
  fprintf( stdout, "tanf           : %f\n", f1);

  f1 = tanhf(M_PI_4);
  fprintf( stdout, "tanhf          : %f\n", f1);

  f1 = tgammaf(2.1);
  fprintf( stdout, "tgammaf        : %f\n", f1);

  f1 = truncf(3.5);
  fprintf( stdout, "truncf         : %f\n", f1);

  f1 = y0f(1.2);
  fprintf( stdout, "y0f            : %f\n", f1);

  f1 = y1f(1.2);
  fprintf( stdout, "y1f            : %f\n", f1);

  f1 = ynf(3,1.2);
  fprintf( stdout, "ynf            : %f\n", f1);
#endif
}
Ejemplo n.º 23
0
__host__ void single_precision_math_functions()
{
    int iX;
    float fX, fY;

    acosf(1.0f);
    acoshf(1.0f);
    asinf(0.0f);
    asinhf(0.0f);
    atan2f(0.0f, 1.0f);
    atanf(0.0f);
    atanhf(0.0f);
    cbrtf(0.0f);
    ceilf(0.0f);
    copysignf(1.0f, -2.0f);
    cosf(0.0f);
    coshf(0.0f);
    //cospif(0.0f);
    //cyl_bessel_i0f(0.0f);
    //cyl_bessel_i1f(0.0f);
    erfcf(0.0f);
    //erfcinvf(2.0f);
    //erfcxf(0.0f);
    erff(0.0f);
    //erfinvf(1.0f);
    exp10f(0.0f);
    exp2f(0.0f);
    expf(0.0f);
    expm1f(0.0f);
    fabsf(1.0f);
    fdimf(1.0f, 0.0f);
    //fdividef(0.0f, 1.0f);
    floorf(0.0f);
    fmaf(1.0f, 2.0f, 3.0f);
    fmaxf(0.0f, 0.0f);
    fminf(0.0f, 0.0f);
    fmodf(0.0f, 1.0f);
    frexpf(0.0f, &iX);
    hypotf(1.0f, 0.0f);
    ilogbf(1.0f);
    isfinite(0.0f);
    isinf(0.0f);
    isnan(0.0f);
    ///j0f(0.0f);
    ///j1f(0.0f);
    ///jnf(-1.0f, 1.0f);
    ldexpf(0.0f, 0);
    ///lgammaf(1.0f);
    ///llrintf(0.0f);
    ///llroundf(0.0f);
    log10f(1.0f);
    log1pf(-1.0f);
    log2f(1.0f);
    logbf(1.0f);
    logf(1.0f);
    ///lrintf(0.0f);
    ///lroundf(0.0f);
    modff(0.0f, &fX);
    ///nanf("1");
    nearbyintf(0.0f);
    //nextafterf(0.0f);
    //norm3df(1.0f, 0.0f, 0.0f);
    //norm4df(1.0f, 0.0f, 0.0f, 0.0f);
    //normcdff(0.0f);
    //normcdfinvf(1.0f);
    //fX = 1.0f; normf(1, &fX);
    powf(1.0f, 0.0f);
    //rcbrtf(1.0f);
    remainderf(2.0f, 1.0f);
    remquof(1.0f, 2.0f, &iX);
    //rhypotf(0.0f, 1.0f);
    ///rintf(1.0f);
    //rnorm3df(0.0f, 0.0f, 1.0f);
    //rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
    //fX = 1.0f; rnormf(1, &fX);
    roundf(0.0f);
    //rsqrtf(1.0f);
    ///scalblnf(0.0f, 1);
    scalbnf(0.0f, 1);
    signbit(1.0f);
    sincosf(0.0f, &fX, &fY);
    //sincospif(0.0f, &fX, &fY);
    sinf(0.0f);
    sinhf(0.0f);
    //sinpif(0.0f);
    sqrtf(0.0f);
    tanf(0.0f);
    tanhf(0.0f);
    tgammaf(2.0f);
    truncf(0.0f);
    ///y0f(1.0f);
    ///y1f(1.0f);
    ///ynf(1, 1.0f);
}
Ejemplo n.º 24
0
TEST(math, scalbnf) {
  ASSERT_FLOAT_EQ(12.0f, scalbnf(3.0f, 2));
}
Ejemplo n.º 25
0
TEST(math, frexpf) {
  int exp;
  float fr = frexpf(1024.0f, &exp);
  ASSERT_FLOAT_EQ(1024.0f, scalbnf(fr, exp));
}
Ejemplo n.º 26
0
// https://code.google.com/p/android/issues/detail?id=6697
TEST(math, frexpf_public_bug_6697) {
  int exp;
  float fr = frexpf(14.1f, &exp);
  ASSERT_FLOAT_EQ(14.1f, scalbnf(fr, exp));
}
Ejemplo n.º 27
0
void runSuccess() {
    scalbnf(1.0f, 1);
    scalbnf(0.0f, 0);
    scalbnf(-1.0f, -1);
    scalbnf(anyfloat(), anyint());
}
Ejemplo n.º 28
0
int main(int argc, char *argv[])
{
  float x;
  x = scalbnf((float) argc, 1);
  return 0;
}
Ejemplo n.º 29
0
float significandf(float x)
{
	return scalbnf(x, -ilogbf(x));
}
Ejemplo n.º 30
0
__global__ void FloatMathPrecise() {
    int iX;
    float fX, fY;

    acosf(1.0f);
    acoshf(1.0f);
    asinf(0.0f);
    asinhf(0.0f);
    atan2f(0.0f, 1.0f);
    atanf(0.0f);
    atanhf(0.0f);
    cbrtf(0.0f);
    fX = ceilf(0.0f);
    fX = copysignf(1.0f, -2.0f);
    cosf(0.0f);
    coshf(0.0f);
    cospif(0.0f);
    cyl_bessel_i0f(0.0f);
    cyl_bessel_i1f(0.0f);
    erfcf(0.0f);
    erfcinvf(2.0f);
    erfcxf(0.0f);
    erff(0.0f);
    erfinvf(1.0f);
    exp10f(0.0f);
    exp2f(0.0f);
    expf(0.0f);
    expm1f(0.0f);
    fX = fabsf(1.0f);
    fdimf(1.0f, 0.0f);
    fdividef(0.0f, 1.0f);
    fX = floorf(0.0f);
    fmaf(1.0f, 2.0f, 3.0f);
    fX = fmaxf(0.0f, 0.0f);
    fX = fminf(0.0f, 0.0f);
    fmodf(0.0f, 1.0f);
    frexpf(0.0f, &iX);
    hypotf(1.0f, 0.0f);
    ilogbf(1.0f);
    isfinite(0.0f);
    fX = isinf(0.0f);
    fX = isnan(0.0f);
    j0f(0.0f);
    j1f(0.0f);
    jnf(-1.0f, 1.0f);
    ldexpf(0.0f, 0);
    lgammaf(1.0f);
    llrintf(0.0f);
    llroundf(0.0f);
    log10f(1.0f);
    log1pf(-1.0f);
    log2f(1.0f);
    logbf(1.0f);
    logf(1.0f);
    lrintf(0.0f);
    lroundf(0.0f);
    modff(0.0f, &fX);
    fX = nanf("1");
    fX = nearbyintf(0.0f);
    nextafterf(0.0f, 0.0f);
    norm3df(1.0f, 0.0f, 0.0f);
    norm4df(1.0f, 0.0f, 0.0f, 0.0f);
    normcdff(0.0f);
    normcdfinvf(1.0f);
    fX = 1.0f;
    normf(1, &fX);
    powf(1.0f, 0.0f);
    rcbrtf(1.0f);
    remainderf(2.0f, 1.0f);
    remquof(1.0f, 2.0f, &iX);
    rhypotf(0.0f, 1.0f);
    fY = rintf(1.0f);
    rnorm3df(0.0f, 0.0f, 1.0f);
    rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
    fX = 1.0f;
    rnormf(1, &fX);
    fY = roundf(0.0f);
    rsqrtf(1.0f);
    scalblnf(0.0f, 1);
    scalbnf(0.0f, 1);
    signbit(1.0f);
    sincosf(0.0f, &fX, &fY);
    sincospif(0.0f, &fX, &fY);
    sinf(0.0f);
    sinhf(0.0f);
    sinpif(0.0f);
    sqrtf(0.0f);
    tanf(0.0f);
    tanhf(0.0f);
    tgammaf(2.0f);
    fY = truncf(0.0f);
    y0f(1.0f);
    y1f(1.0f);
    ynf(1, 1.0f);
}