Exemplo n.º 1
0
float _Complex
__mulsc3(float fa, float fb, float fc, float fd)
{
	union uf ua, ub, uc, ud, ux, uy, uac, ubd, uad, ubc;

	ua.f = fa;
	ub.f = fb;
	uc.f = fc;
	ud.f = fd;

	uac.f = ua.f * uc.f;
	ubd.f = ub.f * ud.f;
	uad.f = ua.f * ud.f;
	ubc.f = ub.f * uc.f;

	ux.f=uac.f-ubd.f;
	uy.f=uad.f+ubc.f;


	if (FLOAT_ISNAN(ux) && FLOAT_ISNAN(uy)) {
		/* Recover infinities that computed as NaN+iNaN ... */
		int recalc = 0;
		if (FLOAT_ISINF(ua) || FLOAT_ISINF(ub) ) { // z is infinite
			/* "Box" the infinity and change NaNs
			   in the other factor to 0 */
			ua.f = pcc_copysignf(FLOAT_ISINF(ua) ? 1.0 : 0.0, ua.f);
			ub.f = pcc_copysignf(FLOAT_ISINF(ub) ? 1.0 : 0.0, ub.f);
			if (FLOAT_ISNAN(uc)) uc.f = pcc_copysignf(0.0, uc.f);
			if (FLOAT_ISNAN(ud)) ud.f = pcc_copysignf(0.0, ud.f);
			recalc = 1;
		}
		if (FLOAT_ISINF(uc) || FLOAT_ISINF(ud) ) { // w is infinite
			/* "Box" the infinity and change NaNs
			    in the other factor to 0 */
			uc.f = pcc_copysignf(FLOAT_ISINF(uc) ? 1.0 : 0.0, uc.f);
			ud.f = pcc_copysignf(FLOAT_ISINF(ud) ? 1.0 : 0.0, ud.f);
			if (FLOAT_ISNAN(ua)) ua.f = pcc_copysignf(0.0, ua.f);
			if (FLOAT_ISNAN(ub)) ub.f = pcc_copysignf(0.0, ub.f);
			recalc = 1;
		}
		if (!recalc && (FLOAT_ISINF(uac) || FLOAT_ISINF(ubd) ||
		    FLOAT_ISINF(uad) || FLOAT_ISINF(ubc))) {
			/* Recover infinities from overflow by
			   changing NaNs to 0 ... */
			if (FLOAT_ISNAN(ua)) ua.f = pcc_copysignf(0.0, ua.f);
			if (FLOAT_ISNAN(ub)) ub.f = pcc_copysignf(0.0, ub.f);
			if (FLOAT_ISNAN(uc)) uc.f = pcc_copysignf(0.0, uc.f);
			if (FLOAT_ISNAN(ud)) ud.f = pcc_copysignf(0.0, ud.f);
			recalc = 1;
		}
		if (recalc) {
			ux.f = __builtin_inff() * ( ua.f * uc.f - ub.f * ud.f );
			uy.f = __builtin_inff() * ( ua.f * ud.f + ub.f * uc.f );
		}
	}
	return ux.f + 1.0iF * uy.f;
}
Exemplo n.º 2
0
void testf(float f, float i)
{
#ifndef __SPU__
  /* The SPU single-precision floating point format does not support Inf.  */

  if (f == __builtin_inff())
    abort ();
  if (f == -__builtin_inff())
    abort ();
  if (i == -__builtin_inff())
    abort ();
  if (i != __builtin_inff())
    abort ();

  if (f >= __builtin_inff())
    abort ();
  if (f > __builtin_inff())
    abort ();
  if (i > __builtin_inff())
    abort ();
  if (f <= -__builtin_inff())
    abort ();
  if (f < -__builtin_inff())
    abort ();
#endif
}
Exemplo n.º 3
0
int main(void) {
  assert(floor(2.7) == 2.0);
  assert(floor(-2.7) == -3.0);
  double c = floor(-0.0);
  assert(c == -0.0);
  assert(sizeof(c) == sizeof(float) ?
    __signbitf(c) : sizeof(c) == sizeof(double) ? __signbit(c) : __signbitl(c));
  c = floor(-(__builtin_inff()));
  assert(sizeof((__builtin_inff())) == sizeof(float) ? __isinff((__builtin_inff())) :
    sizeof((__builtin_inff())) == sizeof(double) ? __isinf((__builtin_inff())) : __isinfl((__builtin_inff())));
  assert(sizeof(c) == sizeof(float) ?
    __signbitf(c) : sizeof(c) == sizeof(double) ? __signbit(c) : __signbitl(c));
  return 0;
}
int
main ()
{
  double nan = __builtin_nan ("");
  float nanf = __builtin_nanf ("");
  long double nanl = __builtin_nanl ("");

  double pinf = __builtin_inf ();
  float pinff = __builtin_inff ();
  long double pinfl = __builtin_infl ();

  if (__builtin_finite (pinf))
    link_error ();
  if (__builtin_finitef (pinff))
    link_error ();
  if (__builtin_finitel (pinfl))
    link_error ();

  if (__builtin_finite (nan))
    link_error ();
  if (__builtin_finitef (nanf))
    link_error ();
  if (__builtin_finitel (nanl))
    link_error ();

  if (!__builtin_finite (4.0))
    link_error ();
  if (!__builtin_finitef (4.0))
    link_error ();
  if (!__builtin_finitel (4.0))
    link_error ();
}
Exemplo n.º 5
0
int main()
{
  test (34.0, __builtin_inf());
  testf (34.0f, __builtin_inff());
  testf (34.0l, __builtin_infl());
  return 0;
}
Exemplo n.º 6
0
int __fpclassifyf( float x )
{
    x = __builtin_fabsf(x);
    if( EXPECT_FALSE( x == 0.0f ) )
        return FP_ZERO;
        
    if( EXPECT_FALSE( x < 0x1.0p-126f ) )
        return FP_SUBNORMAL;
    
    if( EXPECT_TRUE( x < __builtin_inff() ) )
        return FP_NORMAL;
        
    if( EXPECT_TRUE( x == __builtin_inff() ) )
        return FP_INFINITE;

    return FP_NAN;
}
Exemplo n.º 7
0
static int
do_test (void)
{
  int result = 0;

  if (FLT_EVAL_METHOD == 1 || FLT_EVAL_METHOD == 2 || FLT_EVAL_METHOD > 32)
    {
      /* Excess precision for float.  */
      if (iseqsig (1.0f, 1.0f + (float) DBL_EPSILON))
	{
	  puts ("iseqsig removes excess precision float -> double");
	  result = 1;
	}
      else
	puts ("iseqsig preserves excess precision float -> double");
      if (iseqsig (__builtin_inff (), FLT_MAX * FLT_MAX))
	{
	  puts ("iseqsig removes excess range float -> double");
	  result = 1;
	}
      else
	puts ("iseqsig preserves excess range float -> double");
    }

  if (FLT_EVAL_METHOD == 2 || FLT_EVAL_METHOD > 64)
    {
      /* Excess precision for float and double.  */
      if (iseqsig (1.0f, 1.0f + (float) LDBL_EPSILON))
	{
	  puts ("iseqsig removes excess precision float -> long double");
	  result = 1;
	}
      else
	puts ("iseqsig preserves excess precision float -> long double");
      if (iseqsig (1.0, 1.0 + (double) LDBL_EPSILON))
	{
	  puts ("iseqsig removes excess precision double -> long double");
	  result = 1;
	}
      else
	puts ("iseqsig preserves excess precision double -> long double");
      if (LDBL_MAX_EXP >= 2 * DBL_MAX_EXP)
	{
	  if (iseqsig (__builtin_inf (), DBL_MAX * DBL_MAX))
	    {
	      puts ("iseqsig removes excess range double -> long double");
	      result = 1;
	    }
	    else
	      puts ("iseqsig preserves excess range double -> long double");
	}
    }

  return result;
}
Exemplo n.º 8
0
int main()
{
	/*
	 * Return inf means infinity,and return NAN means not a number.
	 */
	printf("The __builtin_inf():[%lf]\n",
			__builtin_inf());
	printf("The __builtin_inff():[%f]\n",
			__builtin_inff());
	printf("The __builtin_infl:[%Lf]\n",
			__builtin_infl());
	return 0;
}
Exemplo n.º 9
0
void testf (void)
{
  float xxxxx[8];
  int i;
  xxxxx[0] = __builtin_copysignf (1.0, Yf[0]);
  xxxxx[1] = __builtin_copysignf (1.0, Yf[1]);
  xxxxx[2] = __builtin_copysignf (-1.0, Yf[2]);
  xxxxx[3] = __builtin_copysignf (0.0, Yf[3]);
  xxxxx[4] = __builtin_copysignf (-0.0, Yf[4]);
  xxxxx[5] = __builtin_copysignf (-0.0, Yf[5]);
  xxxxx[6] = __builtin_copysignf (__builtin_inff (), Yf[6]);
  xxxxx[7] = __builtin_copysignf (-__builtin_nanf (""), Yf[7]);
  for (i = 0; i < 8; ++i)
    if (__builtin_memcmp (xxxxx+i, Zf+i, sizeof(float)) != 0)
      abort ();
}
Exemplo n.º 10
0
int main() {
  volatile float a = __builtin_nanf("");
  if (__builtin_isfinite(a)) {
    return 1;
  }
  volatile float b = __builtin_inff();
  if (__builtin_isfinite(b)) {
    return 1;
  }
  volatile double c = __builtin_nan("");
  if (__builtin_isfinite(c)) {
    return 1;
  }
  volatile double d = __builtin_inf();
  if (__builtin_isfinite(d)) {
    return 1;
  }
#ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80
  volatile long double e = __builtin_nanl("");
  if (__builtin_isfinite(e)) {
    return 1;
  }
  volatile long double f = __builtin_infl();
  if (__builtin_isfinite(f)) {
    return 1;
  }
#endif
  volatile float g = 0;
  if (!__builtin_isfinite(g)) {
    return 1;
  }
  volatile double h = 0;
  if (!__builtin_isfinite(h)) {
    return 1;
  }
#ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80
  volatile long double i = 0;
  if (!__builtin_isfinite(i)) {
    return 1;
  }
#endif
  return 0;
}
Exemplo n.º 11
0
Arquivo: inf-1.c Projeto: 0day-ci/gcc
int main()
{
#ifndef __SPU__
  /* The SPU single-precision floating point format does not support Inf.  */
  float fi = __builtin_inff();
#endif
  double di = __builtin_inf();
  long double li = __builtin_infl();

  float fh = __builtin_huge_valf();
  double dh = __builtin_huge_val();
  long double lh = __builtin_huge_vall();

#ifndef __SPU__
  if (fi + fi != fi)
    abort ();
#endif
  if (di + di != di)
    abort ();
  if (li + li != li)
    abort ();

#ifndef __SPU__
  if (fi != fh)
    abort ();
#endif
  if (di != dh)
    abort ();
  if (li != lh)
    abort ();

#ifndef __SPU__
  if (fi <= 0)
    abort ();
#endif
  if (di <= 0)
    abort ();
  if (li <= 0)
    abort ();

  return 0;
}
int
main ()
{
  double pinf = __builtin_inf ();
  float pinff = __builtin_inff ();
  long double pinfl = __builtin_infl ();

  if (__builtin_isinf (pinf) != 1)
    link_error ();
  if (__builtin_isinf (pinff) != 1)
    link_error ();
  if (__builtin_isinff (pinff) != 1)
    link_error ();
  if (__builtin_isinf (pinfl) != 1)
    link_error ();
  if (__builtin_isinfl (pinfl) != 1)
    link_error ();

  if (__builtin_isinf (-pinf) != -1)
    link_error ();
  if (__builtin_isinf (-pinff) != -1)
    link_error ();
  if (__builtin_isinff (-pinff) != -1)
    link_error ();
  if (__builtin_isinf (-pinfl) != -1)
    link_error ();
  if (__builtin_isinfl (-pinfl) != -1)
    link_error ();

  if (__builtin_isinf (4.0))
    link_error ();
  if (__builtin_isinf (4.0))
    link_error ();
  if (__builtin_isinff (4.0))
    link_error ();
  if (__builtin_isinf (4.0))
    link_error ();
  if (__builtin_isinfl (4.0))
    link_error ();
}
// RUN: %clang_cc1 -fsyntax-only %s -verify -pedantic

// Math stuff

float        g0 = __builtin_huge_val();
double       g1 = __builtin_huge_valf();
long double  g2 = __builtin_huge_vall();
float        g3 = __builtin_inf();
double       g4 = __builtin_inff();
long double  g5 = __builtin_infl();

// GCC misc stuff

extern int f();

int h0 = __builtin_types_compatible_p(int,float);
//int h1 = __builtin_choose_expr(1, 10, f());
//int h2 = __builtin_expect(0, 0);
int h3 = __builtin_bswap16(0x1234) == 0x3412 ? 1 : f();
int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();

short somefunc();

short t = __builtin_constant_p(5353) ? 42 : somefunc();


void bar()
{
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_csqrtf (__builtin_nanf("")));
#endif
  foo (__builtin_csqrt (__builtin_nan("")));
  fool (__builtin_csqrtl (__builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_csqrtf (__builtin_inff()));
#endif
  foo (__builtin_csqrt (__builtin_inf()));
  fool (__builtin_csqrtl (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_csqrtf (-__builtin_inff()));
#endif
  foo (__builtin_csqrt (-__builtin_inf()));
  fool (__builtin_csqrtl (-__builtin_infl()));

  /* Check for overflow/underflow.  */
  TESTIT (cexp, 1e20);
  TESTIT (cexp, -1e20);
  
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_cpowf (__builtin_nanf(""), 2.5F));
#endif
  foo (__builtin_cpow (__builtin_nan(""), 2.5));
  fool (__builtin_cpowl (__builtin_nanl(""), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, __builtin_nanf("")));
#endif
  foo (__builtin_cpow (2.5, __builtin_nan("")));
  fool (__builtin_cpowl (2.5L, __builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_cpowf (__builtin_inff(), 2.5F));
#endif
  foo (__builtin_cpow (__builtin_inf(), 2.5));
  fool (__builtin_cpowl (__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (-__builtin_inff(), 2.5F));
#endif
  foo (__builtin_cpow (-__builtin_inf(), 2.5));
  fool (__builtin_cpowl (-__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, __builtin_inff()));
#endif
  foo (__builtin_cpow (2.5, __builtin_inf()));
  fool (__builtin_cpowl (2.5L, __builtin_infl()));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, -__builtin_inff()));
#endif
  foo (__builtin_cpow (2.5, -__builtin_inf()));
  fool (__builtin_cpowl (2.5L, -__builtin_infl()));

  /* Check for Inv/NaN return values.  */
  TESTIT2 (cpow, -0.0, -4.5); /* Returns Inf */
  TESTIT2 (cpow, 0.0, -4.5); /* Returns Inf */

  /* Check for overflow/underflow.  */
  foof (__builtin_cpowf (__FLT_MAX__, 3.5F));
  foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, 3.5F));
  foo (__builtin_cpow (__DBL_MAX__, 3.5));
  foo (__builtin_cpow (__DBL_MAX__ * 1.I, 3.5));
  fool (__builtin_cpowl (__LDBL_MAX__, 3.5L));
  fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, 3.5L));
  TESTIT2 (cpow, 2.0, 0x1p50);
  TESTIT2 (cpow, 2.0, 0x1p28);
  TESTIT2 (cpow, 2.0, 0x1p24);
  foof (__builtin_cpowf (__FLT_MAX__, -3.5F));
  foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, -3.5F));
  foo (__builtin_cpow (__DBL_MAX__, -3.5));
  foo (__builtin_cpow (__DBL_MAX__ * 1.I, -3.5));
  fool (__builtin_cpowl (__LDBL_MAX__, -3.5L));
  fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, -3.5L));
  TESTIT2 (cpow, 2.0, -0x1p50);
  TESTIT2 (cpow, 2.0, -0x1p28);
  TESTIT2 (cpow, 2.0, -0x1p24);

}
Exemplo n.º 15
0
float _Complex
__divsc3(float ax, float bx, float cx, float dx)
{
	float denom;
	union uf ua, ub, uc, ud, ur, ulogbw, ux, uy;
	int uci, udi, res, ilogbw = 0;

	ua.f = ax;
	ub.f = bx;
	uc.f = cx;
	ud.f = dx;

	/* fabsf; clear sign */
	uci = uc.i & FLOAT_MANTEXP;
	udi = ud.i & FLOAT_MANTEXP;

	/* fmaxf; ordinary integer compare */
	ur.i = (uci > udi ? uci : udi);

	/* logbf */
	res = ur.i >> 23;
	if (ur.i == 0)
		ulogbw.f = (float)-1.0/ur.f;
	else if (res == 255)
		ulogbw.f = ur.f * ur.f;
	else if (res == 0)
		ulogbw.f = -126.0;
	else
		ulogbw.f = (res-127);

	/* isfinite */
	if (FLOAT_ISFIN(ulogbw)) {
		ilogbw = (int)ulogbw.f;
		uc.f = pcc_scalbnf(uc.f, -ilogbw);
		ud.f = pcc_scalbnf(ud.f, -ilogbw);
	}
	denom = uc.f * uc.f + ud.f * ud.f;
	ux.f = pcc_scalbnf((ua.f * uc.f + ub.f * ud.f) / denom, -ilogbw);
	uy.f = pcc_scalbnf((ub.f * uc.f - ua.f * ud.f) / denom, -ilogbw);

	if (FLOAT_ISNAN(ux) && FLOAT_ISNAN(uy)) {
		if ((denom == 0.0) &&
		    (!FLOAT_ISNAN(ua) || !FLOAT_ISNAN(ub))) {
			ux.f = pcc_copysignf(__builtin_inff(), uc.f) * ua.f;
			uy.f = pcc_copysignf(__builtin_inff(), uc.f) * ub.f;
		} else if ((FLOAT_ISINF(ua) || FLOAT_ISINF(ub)) &&
		    FLOAT_ISFIN(uc) && FLOAT_ISFIN(ud)) {
			ua.f = pcc_copysignf(FLOAT_ISINF(ua) ? 1.0 : 0.0, ua.f);
			ub.f = pcc_copysignf(FLOAT_ISINF(ub) ? 1.0 : 0.0, ub.f);
			ux.f = __builtin_inff() * ( ua.f * uc.f + ub.f * ud.f );
			uy.f = __builtin_inff() * ( ub.f * uc.f - ua.f * ud.f );
		} else if (FLOAT_ISINF(ulogbw) &&
		    FLOAT_ISFIN(ua) && FLOAT_ISFIN(ub)) {
			uc.f = pcc_copysignf(FLOAT_ISINF(uc) ? 1.0 : 0.0, uc.f);
			ud.f = pcc_copysignf(FLOAT_ISINF(ud) ? 1.0 : 0.0, ud.f);
			ux.f = 0.0 * ( ua.f * uc.f + ub.f * ud.f );
			uy.f = 0.0 * ( ub.f * uc.f - ua.f * ud.f );
		}
	}
	return ux.f + 1.0iF * uy.f;
}
Exemplo n.º 16
0
void bar()
{
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_exp2f (__builtin_nanf("")));
#endif
  foo (__builtin_exp2 (__builtin_nan("")));
  fool (__builtin_exp2l (__builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_exp2f (__builtin_inff()));
#endif
  foo (__builtin_exp2 (__builtin_inf()));
  fool (__builtin_exp2l (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_exp2f (-__builtin_inff()));
#endif
  foo (__builtin_exp2 (-__builtin_inf()));
  fool (__builtin_exp2l (-__builtin_infl()));

  /* Result overflows MPFR, which in version 2.2.x has 30 exponent bits.  */
  TESTIT (exp2, 0x1p50);
  /* Result underflows MPFR, which in version 2.2.x has 30 exponent bits.  */
  TESTIT (exp2, -0x1p50);

  /* Result overflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
  TESTIT (exp2, 0x1p28);
  /* Result underflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
  TESTIT (exp2, -0x1p28);
  
  /* Result overflows (even an extended) C double's mode.  */
  TESTIT (exp2, 0x1p24);
  /* Result underflows (even an extended) C double's mode.  */
  TESTIT (exp2, -0x1p24);

  /* Ensure that normal arguments/results are folded.  */
  TESTIT (exp2, 1.5);
  TESTIT (exp2, -1.5);
  
  /* The asin arg must be [-1 ... 1] inclusive.  */
  TESTIT (asin, -1.5);
  TESTIT (asin, 1.5);

  /* The acos arg must be [-1 ... 1] inclusive.  */
  TESTIT (acos, -1.5);
  TESTIT (acos, 1.5);
  
  /* The acosh arg must be [1 ... Inf] inclusive.  */
  TESTIT (acosh, 0.5);

  /* The atanh arg must be [-1 ... 1] EXclusive.  */
  TESTIT (atanh, -1.0);
  TESTIT (atanh, 1.0);

  /* The log* arg must be [0 ... Inf] EXclusive.  */
  TESTIT (log, -1.0);
  TESTIT (log, 0.0);
  TESTIT (log, -0.0);
  
  TESTIT (log2, -1.0);
  TESTIT (log2, 0.0);
  TESTIT (log2, -0.0);
  
  TESTIT (log10, -1.0);
  TESTIT (log10, 0.0);
  TESTIT (log10, -0.0);
  
  /* The log1p arg must be [-1 ... Inf] EXclusive.  */
  TESTIT (log1p, -2.0);
  TESTIT (log1p, -1.0);

  /* The tgamma arg errors with zero or negative integers.  */
  TESTIT (tgamma, 0.0);
  TESTIT (tgamma, -0.0);
  TESTIT (tgamma, -1.0);
  TESTIT (tgamma, -2.0);
  TESTIT (tgamma, -3.0);

  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_powf (__builtin_nanf(""), 2.5F));
#endif
  foo (__builtin_pow (__builtin_nan(""), 2.5));
  fool (__builtin_powl (__builtin_nanl(""), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, __builtin_nanf("")));
#endif
  foo (__builtin_pow (2.5, __builtin_nan("")));
  fool (__builtin_powl (2.5L, __builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_powf (__builtin_inff(), 2.5F));
#endif
  foo (__builtin_pow (__builtin_inf(), 2.5));
  fool (__builtin_powl (__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (-__builtin_inff(), 2.5F));
#endif
  foo (__builtin_pow (-__builtin_inf(), 2.5));
  fool (__builtin_powl (-__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, __builtin_inff()));
#endif
  foo (__builtin_pow (2.5, __builtin_inf()));
  fool (__builtin_powl (2.5L, __builtin_infl()));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, -__builtin_inff()));
#endif
  foo (__builtin_pow (2.5, -__builtin_inf()));
  fool (__builtin_powl (2.5L, -__builtin_infl()));

  /* Check for Inv/NaN return values.  */
  TESTIT2 (pow, -0.0, -4.5); /* Returns Inf */
  TESTIT2 (pow, 0.0, -4.5); /* Returns Inf */
  TESTIT2 (pow, -3.0, -4.5); /* Returns NaN */

  /* Check for overflow/underflow.  */
  foof (__builtin_powf (__FLT_MAX__, 3.5F));
  foo (__builtin_pow (__DBL_MAX__, 3.5));
  fool (__builtin_powl (__LDBL_MAX__, 3.5L));
  TESTIT2 (pow, 2.0, 0x1p50);
  foof (__builtin_powf (__FLT_MAX__, -3.5F));
  foo (__builtin_pow (__DBL_MAX__, -3.5));
  fool (__builtin_powl (__LDBL_MAX__, -3.5L));
  TESTIT2 (pow, 2.0, -0x1p50);
  
  /* The sqrt arg must be [0 ... Inf] inclusive.  */
  TESTIT (sqrt, -0.5);
  TESTIT (sqrt, -0.0);
  TESTIT (sqrt, 0.0);

  /* Check for overflow/underflow.  */

  /* These adjustments are too big.  */
#define FLT_EXP_ADJ (2*(__FLT_MAX_EXP__-__FLT_MIN_EXP__)+1)
#define DBL_EXP_ADJ (2*(__DBL_MAX_EXP__-__DBL_MIN_EXP__)+1)
#define LDBL_EXP_ADJ (2*(__LDBL_MAX_EXP__-__LDBL_MIN_EXP__)+1)

  TESTIT2_I2 (ldexp, 1.0, __INT_MAX__);
  TESTIT2_I2 (ldexp, 1.0, -__INT_MAX__-1);
  TESTIT2_I2 (ldexp, -1.0, __INT_MAX__);
  TESTIT2_I2 (ldexp, -1.0, -__INT_MAX__-1);
  TESTIT2_I2ALL (ldexp, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (ldexp, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (ldexp, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (ldexp, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT2_I2 (scalbn, 1.0, __INT_MAX__);
  TESTIT2_I2 (scalbn, 1.0, -__INT_MAX__-1);
  TESTIT2_I2 (scalbn, -1.0, __INT_MAX__);
  TESTIT2_I2 (scalbn, -1.0, -__INT_MAX__-1);
  TESTIT2_I2ALL (scalbn, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbn, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbn, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (scalbn, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT2_I2 (scalbln, 1.0, __LONG_MAX__);
  TESTIT2_I2 (scalbln, 1.0, -__LONG_MAX__-1);
  TESTIT2_I2 (scalbln, -1.0, __LONG_MAX__);
  TESTIT2_I2 (scalbln, -1.0, -__LONG_MAX__-1);
  TESTIT2_I2ALL (scalbln, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbln, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbln, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (scalbln, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT (logb, 0.0);
  TESTIT (logb, -0.0);

  TESTIT (ilogb, 0.0);
  TESTIT (ilogb, -0.0);

#ifndef __SPU__
  foof (__builtin_ilogbf (__builtin_inff()));
#endif
  foo (__builtin_ilogb (__builtin_inf()));
  fool (__builtin_ilogbl (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_ilogbf (-__builtin_inff()));
#endif
  foo (__builtin_ilogb (-__builtin_inf()));
  fool (__builtin_ilogbl (-__builtin_infl()));

#ifndef __SPU__
  foof (__builtin_ilogbf (__builtin_nanf("")));
#endif
  foo (__builtin_ilogb (__builtin_nan("")));
  fool (__builtin_ilogbl (__builtin_nanl("")));
#ifndef __SPU__
  foof (__builtin_ilogbf (-__builtin_nanf("")));
#endif
  foo (__builtin_ilogb (-__builtin_nan("")));
  fool (__builtin_ilogbl (-__builtin_nanl("")));

  /* The y* arg must be [0 ... Inf] EXclusive.  */
  TESTIT (y0, -1.0);
  TESTIT (y0, 0.0);
  TESTIT (y0, -0.0);

  TESTIT (y1, -1.0);
  TESTIT (y1, 0.0);
  TESTIT (y1, -0.0);

  TESTIT2_I1 (yn, 2, -1.0);
  TESTIT2_I1 (yn, 2, 0.0);
  TESTIT2_I1 (yn, 2, -0.0);

  TESTIT2_I1 (yn, -3, -1.0);
  TESTIT2_I1 (yn, -3, 0.0);
  TESTIT2_I1 (yn, -3, -0.0);

  /* The second argument of remquo/remainder/drem must not be 0.  */
  TESTIT_REMQUO (1.0, 0.0);
  TESTIT_REMQUO (1.0, -0.0);
  TESTIT2 (remainder, 1.0, 0.0);
  TESTIT2 (remainder, 1.0, -0.0);
  TESTIT2 (drem, 1.0, 0.0);
  TESTIT2 (drem, 1.0, -0.0);

  /* The argument to lgamma* cannot be zero or a negative integer.  */
  TESTIT_REENT (lgamma, -4.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -3.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -2.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -1.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -0.0); /* lgamma_r */
  TESTIT_REENT (lgamma, 0.0); /* lgamma_r */
  
  TESTIT_REENT (gamma, -4.0); /* gamma_r */
  TESTIT_REENT (gamma, -3.0); /* gamma_r */
  TESTIT_REENT (gamma, -2.0); /* gamma_r */
  TESTIT_REENT (gamma, -1.0); /* gamma_r */
  TESTIT_REENT (gamma, -0.0); /* gamma_r */
  TESTIT_REENT (gamma, 0.0); /* gamma_r */
}
Exemplo n.º 17
0
int
convert_infnan (st_parameter_dt *dtp, void *dest, const char *buffer,
	        int length)
{
  const char *s = buffer;
  int is_inf, plus = 1;

  if (*s == '+')
    s++;
  else if (*s == '-')
    {
      s++;
      plus = 0;
    }

  is_inf = *s == 'i';

  switch (length)
    {
    case 4:
      if (is_inf)
	*((GFC_REAL_4*) dest) = plus ? __builtin_inff () : -__builtin_inff ();
      else
	*((GFC_REAL_4*) dest) = plus ? __builtin_nanf ("") : -__builtin_nanf ("");
      break;

    case 8:
      if (is_inf)
	*((GFC_REAL_8*) dest) = plus ? __builtin_inf () : -__builtin_inf ();
      else
	*((GFC_REAL_8*) dest) = plus ? __builtin_nan ("") : -__builtin_nan ("");
      break;

#if defined(HAVE_GFC_REAL_10)
    case 10:
      if (is_inf)
	*((GFC_REAL_10*) dest) = plus ? __builtin_infl () : -__builtin_infl ();
      else
	*((GFC_REAL_10*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl ("");
      break;
#endif

#if defined(HAVE_GFC_REAL_16)
# if defined(GFC_REAL_16_IS_FLOAT128)
    case 16:
      *((GFC_REAL_16*) dest) = __qmath_(strtoflt128) (buffer, NULL);
      break;
# else
    case 16:
      if (is_inf)
	*((GFC_REAL_16*) dest) = plus ? __builtin_infl () : -__builtin_infl ();
      else
	*((GFC_REAL_16*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl ("");
      break;
# endif
#endif

    default:
      internal_error (&dtp->common, "Unsupported real kind during IO");
    }

  return 0;
}
Exemplo n.º 18
0
// RUN: clang-cc -emit-llvm %s -o %t

typedef __attribute__(( ext_vector_type(4) )) float float4;
typedef __attribute__(( ext_vector_type(2) )) float float2;
typedef __attribute__(( ext_vector_type(4) )) int int4;

float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };

const float4 bar = (float4){ 1.0, 2.0, 3.0, __builtin_inff() };

float4 test1(float4 V) {
  return V.wzyx+V;
}

float2 vec2, vec2_2;
float4 vec4, vec4_2;
float f;

void test2() {
    vec2 = vec4.xy;  // shorten
    f = vec2.x;      // extract elt
    vec4 = vec4.yyyy;  // splat
    
    vec2.x = f;      // insert one.
    vec2.yx = vec2; // reverse
}

void test3(float4 *out) {
  *out = ((float4) {1.0f, 2.0f, 3.0f, 4.0f });
}
/* { dg-do compile } */

float fi = __builtin_inff();
double di = __builtin_inf();
long double li = __builtin_infl();

float fh = __builtin_huge_valf();
double dh = __builtin_huge_val();
long double lh = __builtin_huge_vall();

/* { dg-warning "does not support infinity" "INF unsupported" { target vax-*-* } 3 } */
/* { dg-warning "does not support infinity" "INF unsupported" { target vax-*-* } 4 } */
/* { dg-warning "does not support infinity" "INF unsupported" { target vax-*-* } 5 } */
Exemplo n.º 20
0
float __inff( void )
{
    return __builtin_inff();
}
Exemplo n.º 21
0
    VERIFY (NZ, NAN, TYPE, COMPARE, CL);		\
    VERIFY (NZ, INF, TYPE, COMPARE, CL);		\
    VERIFY (NAN, PZ, TYPE, COMPARE, CL);		\
    VERIFY (NAN, NZ, TYPE, COMPARE, CL);		\
    VERIFY (NAN, NAN, TYPE, COMPARE, CL);		\
    VERIFY (NAN, INF, TYPE, COMPARE, CL);		\
    VERIFY (INF, PZ, TYPE, COMPARE,CL);			\
    VERIFY (INF, NZ, TYPE, COMPARE, CL);		\
    VERIFY (INF, NAN, TYPE, COMPARE, CL);		\
    VERIFY (INF, INF, TYPE, COMPARE, CL);		\
  } while (0)

static void
check_float (void)
{
  ALL_CHECKS (0.0f, -0.0f, __builtin_nanf (""), __builtin_inff (),
	      float, comparecf, CMPLXF);
}

static void
check_double (void)
{
  ALL_CHECKS (0.0, -0.0, __builtin_nan (""), __builtin_inf (),
	      double, comparec, CMPLX);
}

static void
check_long_double (void)
{
  ALL_CHECKS (0.0l, -0.0l, __builtin_nanl (""), __builtin_infl (),
	      long double, comparecl, CMPLXL);
Exemplo n.º 22
0
double _Complex
__divdc3(double ax, double bx, double cx, double dx)
{
	double denom;
	union ud ua, ub, uc, ud, ur, ulogbw, ux, uy;
	int uci, udi, res, ilogbw = 0;

	ua.f = ax;
	ub.f = bx;
	uc.f = cx;
	ud.f = dx;

	/* fabsf; clear sign */
	uci = uc.dih & DOUBLE_MANTEXP;
	udi = ud.dih & DOUBLE_MANTEXP;

	/* fmaxf; ordinary integer compare */
	if ((uci > udi) || (uci == udi && uc.dil > ud.dil)) {
		ur.dih = uci;
		ur.dil = uc.dil;
	} else {
		ur.dih = udi;
		ur.dil = ud.dil;
	}

	/* logbf */
	res = ur.dih >> 20;
	if (ur.dih == 0 && ur.dil == 0)
		ulogbw.f = (double)-1.0/ur.f;
	else if (res == 2047)
		ulogbw.f = ur.f * ur.f;
	else if (res == 0)
		ulogbw.f = -1022.0;
	else
		ulogbw.f = (res-1023);

	/* isfinite */
	if (DOUBLE_ISFIN(ulogbw)) {
		ilogbw = (int)ulogbw.f;
		uc.f = pcc_scalbn(uc.f, -ilogbw);
		ud.f = pcc_scalbn(ud.f, -ilogbw);
	}
	denom = uc.f * uc.f + ud.f * ud.f;
	ux.f = pcc_scalbn((ua.f * uc.f + ub.f * ud.f) / denom, -ilogbw);
	uy.f = pcc_scalbn((ub.f * uc.f - ua.f * ud.f) / denom, -ilogbw);

	if (DOUBLE_ISNAN(ux) && DOUBLE_ISNAN(uy)) {
		if ((denom == 0.0) &&
		    (!DOUBLE_ISNAN(ua) || !DOUBLE_ISNAN(ub))) {
			ux.f = pcc_copysign(__builtin_inff(), uc.f) * ua.f;
			uy.f = pcc_copysign(__builtin_inff(), uc.f) * ub.f;
		} else if ((DOUBLE_ISINF(ua) || DOUBLE_ISINF(ub)) &&
		    DOUBLE_ISFIN(uc) && DOUBLE_ISFIN(ud)) {
			ua.f = pcc_copysign(DOUBLE_ISINF(ua) ? 1.0 : 0.0, ua.f);
			ub.f = pcc_copysign(DOUBLE_ISINF(ub) ? 1.0 : 0.0, ub.f);
			ux.f = __builtin_inf() * ( ua.f * uc.f + ub.f * ud.f );
			uy.f = __builtin_inf() * ( ub.f * uc.f - ua.f * ud.f );
		} else if (DOUBLE_ISINF(ulogbw) &&
		    DOUBLE_ISFIN(ua) && DOUBLE_ISFIN(ub)) {
			uc.f = pcc_copysign(DOUBLE_ISINF(uc) ? 1.0 : 0.0, uc.f);
			ud.f = pcc_copysign(DOUBLE_ISINF(ud) ? 1.0 : 0.0, ud.f);
			ux.f = 0.0 * ( ua.f * uc.f + ub.f * ud.f );
			uy.f = 0.0 * ( ub.f * uc.f - ua.f * ud.f );
		}
	}
	return ux.f + 1.0iF * uy.f;
}
Exemplo n.º 23
0
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Math stuff

double       g0  = __builtin_huge_val();
float        g1  = __builtin_huge_valf();
long double  g2  = __builtin_huge_vall();

double       g3  = __builtin_inf();
float        g4  = __builtin_inff();
long double  g5  = __builtin_infl();

double       g6  = __builtin_nan("");
float        g7  = __builtin_nanf("");
long double  g8  = __builtin_nanl("");

// GCC constant folds these too (via native strtol):
//double       g6_1  = __builtin_nan("1");
//float        g7_1  = __builtin_nanf("1");
//long double  g8_1  = __builtin_nanl("1");

// APFloat doesn't have signalling NaN functions.
//double       g9  = __builtin_nans("");
//float        g10 = __builtin_nansf("");
//long double  g11 = __builtin_nansl("");

//int          g12 = __builtin_abs(-12);

double       g13 = __builtin_fabs(-12.);
double       g13_0 = __builtin_fabs(-0.);
double       g13_1 = __builtin_fabs(-__builtin_inf());
Exemplo n.º 24
0
/* { dg-do compile } */
/* { dg-options "-O2 -ftree-vectorize -mavx -mtune=generic" } */
/* { dg-skip-if "" { x86_64-*-mingw* } { "*" } { "" } } */
/* { dg-final { scan-assembler "and\[lq\]?\[\\t \]*\\$-32,\[\\t \]*%\[re\]?sp" } } */
/* { dg-final { scan-assembler "vmovaps\[\\t \]*%ymm" } } */

extern void abort (void);

static float Yf[] = { 2.0, -2.0, -2.0, -2.0, -2.0, 2.0, -0.0, __builtin_inff () };
static const float Zf[] = { 1.0, -1.0, -1.0, -0.0, -0.0, 0.0, -__builtin_inff (), __builtin_nanf ("") };

void testf (void)
{
  float xxxxx[8];
  int i;
  xxxxx[0] = __builtin_copysignf (1.0, Yf[0]);
  xxxxx[1] = __builtin_copysignf (1.0, Yf[1]);
  xxxxx[2] = __builtin_copysignf (-1.0, Yf[2]);
  xxxxx[3] = __builtin_copysignf (0.0, Yf[3]);
  xxxxx[4] = __builtin_copysignf (-0.0, Yf[4]);
  xxxxx[5] = __builtin_copysignf (-0.0, Yf[5]);
  xxxxx[6] = __builtin_copysignf (__builtin_inff (), Yf[6]);
  xxxxx[7] = __builtin_copysignf (-__builtin_nanf (""), Yf[7]);
  for (i = 0; i < 8; ++i)
    if (__builtin_memcmp (xxxxx+i, Zf+i, sizeof(float)) != 0)
      abort ();
}