Esempio n. 1
0
COMPILER_RT_ABI Fcomplex __divsc3(float __a, float __b, float __c, float __d) {
  int __ilogbw = 0;
  float __logbw =
      __compiler_rt_logbf(crt_fmaxf(crt_fabsf(__c), crt_fabsf(__d)));
  if (crt_isfinite(__logbw)) {
    __ilogbw = (int)__logbw;
    __c = crt_scalbnf(__c, -__ilogbw);
    __d = crt_scalbnf(__d, -__ilogbw);
  }
  float __denom = __c * __c + __d * __d;
  Fcomplex z;
  COMPLEX_REAL(z) = crt_scalbnf((__a * __c + __b * __d) / __denom, -__ilogbw);
  COMPLEX_IMAGINARY(z) =
      crt_scalbnf((__b * __c - __a * __d) / __denom, -__ilogbw);
  if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
    if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b))) {
      COMPLEX_REAL(z) = crt_copysignf(CRT_INFINITY, __c) * __a;
      COMPLEX_IMAGINARY(z) = crt_copysignf(CRT_INFINITY, __c) * __b;
    } else if ((crt_isinf(__a) || crt_isinf(__b)) && crt_isfinite(__c) &&
               crt_isfinite(__d)) {
      __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
      __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
      COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
      COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
    } else if (crt_isinf(__logbw) && __logbw > 0 && crt_isfinite(__a) &&
               crt_isfinite(__b)) {
      __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
      __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
      COMPLEX_REAL(z) = 0 * (__a * __c + __b * __d);
      COMPLEX_IMAGINARY(z) = 0 * (__b * __c - __a * __d);
    }
  }
  return z;
}
float __compilerrt_fmaxf(float x, float y)
{
  if (crt_isnan(x))
    return y;
  if (crt_isnan(y))
    return x;
  return x > y ? x : y;
}
Esempio n. 3
0
double _Complex
__muldc3(double __a, double __b, double __c, double __d)
{
    double __ac = __a * __c;
    double __bd = __b * __d;
    double __ad = __a * __d;
    double __bc = __b * __c;
    double _Complex z;
    __real__ z = __ac - __bd;
    __imag__ z = __ad + __bc;
    if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
    {
        int __recalc = 0;
        if (crt_isinf(__a) || crt_isinf(__b))
        {
            __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
            __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
            if (crt_isnan(__c))
                __c = crt_copysign(0, __c);
            if (crt_isnan(__d))
                __d = crt_copysign(0, __d);
            __recalc = 1;
        }
        if (crt_isinf(__c) || crt_isinf(__d))
        {
            __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
            __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
            if (crt_isnan(__a))
                __a = crt_copysign(0, __a);
            if (crt_isnan(__b))
                __b = crt_copysign(0, __b);
            __recalc = 1;
        }
        if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
                          crt_isinf(__ad) || crt_isinf(__bc)))
        {
            if (crt_isnan(__a))
                __a = crt_copysign(0, __a);
            if (crt_isnan(__b))
                __b = crt_copysign(0, __b);
            if (crt_isnan(__c))
                __c = crt_copysign(0, __c);
            if (crt_isnan(__d))
                __d = crt_copysign(0, __d);
            __recalc = 1;
        }
        if (__recalc)
        {
            __real__ z = CRT_INFINITY * (__a * __c - __b * __d);
            __imag__ z = CRT_INFINITY * (__a * __d + __b * __c);
        }
    }
    return z;
}
Esempio n. 4
0
COMPILER_RT_ABI long double _Complex
__multc3(long double a, long double b, long double c, long double d)
{
    long double ac = a * c;
    long double bd = b * d;
    long double ad = a * d;
    long double bc = b * c;
    long double _Complex z;
    __real__ z = ac - bd;
    __imag__ z = ad + bc;
    if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) {
        int recalc = 0;
        if (crt_isinf(a) || crt_isinf(b)) {
            a = crt_copysignl(crt_isinf(a) ? 1 : 0, a);
            b = crt_copysignl(crt_isinf(b) ? 1 : 0, b);
            if (crt_isnan(c))
                c = crt_copysignl(0, c);
            if (crt_isnan(d))
                d = crt_copysignl(0, d);
            recalc = 1;
        }
        if (crt_isinf(c) || crt_isinf(d)) {
            c = crt_copysignl(crt_isinf(c) ? 1 : 0, c);
            d = crt_copysignl(crt_isinf(d) ? 1 : 0, d);
            if (crt_isnan(a))
                a = crt_copysignl(0, a);
            if (crt_isnan(b))
                b = crt_copysignl(0, b);
            recalc = 1;
        }
        if (!recalc && (crt_isinf(ac) || crt_isinf(bd) ||
                          crt_isinf(ad) || crt_isinf(bc))) {
            if (crt_isnan(a))
                a = crt_copysignl(0, a);
            if (crt_isnan(b))
                b = crt_copysignl(0, b);
            if (crt_isnan(c))
                c = crt_copysignl(0, c);
            if (crt_isnan(d))
                d = crt_copysignl(0, d);
            recalc = 1;
        }
        if (recalc) {
            __real__ z = CRT_INFINITY * (a * c - b * d);
            __imag__ z = CRT_INFINITY * (a * d + b * c);
        }
    }
    return z;
}
Esempio n. 5
0
COMPILER_RT_ABI Dcomplex __muldc3(double __a, double __b, double __c,
                                  double __d) {
  double __ac = __a * __c;
  double __bd = __b * __d;
  double __ad = __a * __d;
  double __bc = __b * __c;
  Dcomplex z;
  COMPLEX_REAL(z) = __ac - __bd;
  COMPLEX_IMAGINARY(z) = __ad + __bc;
  if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
    int __recalc = 0;
    if (crt_isinf(__a) || crt_isinf(__b)) {
      __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
      __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
      if (crt_isnan(__c))
        __c = crt_copysign(0, __c);
      if (crt_isnan(__d))
        __d = crt_copysign(0, __d);
      __recalc = 1;
    }
    if (crt_isinf(__c) || crt_isinf(__d)) {
      __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
      __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
      if (crt_isnan(__a))
        __a = crt_copysign(0, __a);
      if (crt_isnan(__b))
        __b = crt_copysign(0, __b);
      __recalc = 1;
    }
    if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||
                      crt_isinf(__bc))) {
      if (crt_isnan(__a))
        __a = crt_copysign(0, __a);
      if (crt_isnan(__b))
        __b = crt_copysign(0, __b);
      if (crt_isnan(__c))
        __c = crt_copysign(0, __c);
      if (crt_isnan(__d))
        __d = crt_copysign(0, __d);
      __recalc = 1;
    }
    if (__recalc) {
      COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
      COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
    }
  }
  return z;
}
Esempio n. 6
0
File: divxc3.c Progetto: 0mp/freebsd
COMPILER_RT_ABI Lcomplex
__divxc3(long double __a, long double __b, long double __c, long double __d)
{
    int __ilogbw = 0;
    long double __logbw = crt_logbl(crt_fmaxl(crt_fabsl(__c), crt_fabsl(__d)));
    if (crt_isfinite(__logbw))
    {
        __ilogbw = (int)__logbw;
        __c = crt_scalbnl(__c, -__ilogbw);
        __d = crt_scalbnl(__d, -__ilogbw);
    }
    long double __denom = __c * __c + __d * __d;
    Lcomplex z;
    COMPLEX_REAL(z) = crt_scalbnl((__a * __c + __b * __d) / __denom, -__ilogbw);
    COMPLEX_IMAGINARY(z) = crt_scalbnl((__b * __c - __a * __d) / __denom, -__ilogbw);
    if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
    {
        if ((__denom == 0) && (!crt_isnan(__a) || !crt_isnan(__b)))
        {
            COMPLEX_REAL(z) = crt_copysignl(CRT_INFINITY, __c) * __a;
            COMPLEX_IMAGINARY(z) = crt_copysignl(CRT_INFINITY, __c) * __b;
        }
        else if ((crt_isinf(__a) || crt_isinf(__b)) &&
                 crt_isfinite(__c) && crt_isfinite(__d))
        {
            __a = crt_copysignl(crt_isinf(__a) ? 1 : 0, __a);
            __b = crt_copysignl(crt_isinf(__b) ? 1 : 0, __b);
            COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
            COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
        }
        else if (crt_isinf(__logbw) && __logbw > 0 &&
                 crt_isfinite(__a) && crt_isfinite(__b))
        {
            __c = crt_copysignl(crt_isinf(__c) ? 1 : 0, __c);
            __d = crt_copysignl(crt_isinf(__d) ? 1 : 0, __d);
            COMPLEX_REAL(z) = 0 * (__a * __c + __b * __d);
            COMPLEX_IMAGINARY(z) = 0 * (__b * __c - __a * __d);
        }
    }
    return z;
}
Esempio n. 7
0
double _Complex
__divdc3(double __a, double __b, double __c, double __d)
{
    int __ilogbw = 0;
    double __logbw = crt_logb(crt_fmax(crt_fabs(__c), crt_fabs(__d)));
    if (crt_isfinite(__logbw))
    {
        __ilogbw = (int)__logbw;
        __c = crt_scalbn(__c, -__ilogbw);
        __d = crt_scalbn(__d, -__ilogbw);
    }
    double __denom = __c * __c + __d * __d;
    double _Complex z;
    __real__ z = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
    __imag__ z = crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
    if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
    {
        if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b)))
        {
            __real__ z = crt_copysign(CRT_INFINITY, __c) * __a;
            __imag__ z = crt_copysign(CRT_INFINITY, __c) * __b;
        }
        else if ((crt_isinf(__a) || crt_isinf(__b)) &&
                 crt_isfinite(__c) && crt_isfinite(__d))
        {
            __a = crt_copysign(crt_isinf(__a) ? 1.0 : 0.0, __a);
            __b = crt_copysign(crt_isinf(__b) ? 1.0 : 0.0, __b);
            __real__ z = CRT_INFINITY * (__a * __c + __b * __d);
            __imag__ z = CRT_INFINITY * (__b * __c - __a * __d);
        }
        else if (crt_isinf(__logbw) && __logbw > 0.0 &&
                 crt_isfinite(__a) && crt_isfinite(__b))
        {
            __c = crt_copysign(crt_isinf(__c) ? 1.0 : 0.0, __c);
            __d = crt_copysign(crt_isinf(__d) ? 1.0 : 0.0, __d);
            __real__ z = 0.0 * (__a * __c + __b * __d);
            __imag__ z = 0.0 * (__b * __c - __a * __d);
        }
    }
    return z;
}
Esempio n. 8
0
COMPILER_RT_ABI Dcomplex
__divdc3(double __a, double __b, double __c, double __d)
{
    int __ilogbw = 0;
    double __logbw = crt_logb(crt_fmax(crt_fabs(__c), crt_fabs(__d)));
    if (crt_isfinite(__logbw))
    {
        __ilogbw = (int)__logbw;
        __c = crt_scalbn(__c, -__ilogbw);
        __d = crt_scalbn(__d, -__ilogbw);
    }
    double __denom = __c * __c + __d * __d;
    Dcomplex z;
    COMPLEX_REAL(z) = crt_scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
    COMPLEX_IMAGINARY(z) = crt_scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
    if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
    {
        if ((__denom == 0.0) && (!crt_isnan(__a) || !crt_isnan(__b)))
        {
            COMPLEX_REAL(z) = crt_copysign(CRT_INFINITY, __c) * __a;
            COMPLEX_IMAGINARY(z) = crt_copysign(CRT_INFINITY, __c) * __b;
        }
        else if ((crt_isinf(__a) || crt_isinf(__b)) &&
                 crt_isfinite(__c) && crt_isfinite(__d))
        {
            __a = crt_copysign(crt_isinf(__a) ? 1.0 : 0.0, __a);
            __b = crt_copysign(crt_isinf(__b) ? 1.0 : 0.0, __b);
            COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c + __b * __d);
            COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__b * __c - __a * __d);
        }
        else if (crt_isinf(__logbw) && __logbw > 0.0 &&
                 crt_isfinite(__a) && crt_isfinite(__b))
        {
            __c = crt_copysign(crt_isinf(__c) ? 1.0 : 0.0, __c);
            __d = crt_copysign(crt_isinf(__d) ? 1.0 : 0.0, __d);
            COMPLEX_REAL(z) = 0.0 * (__a * __c + __b * __d);
            COMPLEX_IMAGINARY(z) = 0.0 * (__b * __c - __a * __d);
        }
    }
    return z;
}
Esempio n. 9
0
long double _Complex
__multc3(long double a, long double b, long double c, long double d)
{
	long double ac = __gcc_qmul(a,c);
	long double bd = __gcc_qmul(b,d);
	long double ad = __gcc_qmul(a,d);
	long double bc = __gcc_qmul(b,c);
	
	DD real = { .ld = __gcc_qsub(ac,bd) };
	DD imag = { .ld = __gcc_qadd(ad,bc) };
	
	if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi))
	{
		int recalc = 0;
		
		DD aDD = { .ld = a };
		DD bDD = { .ld = b };
		DD cDD = { .ld = c };
		DD dDD = { .ld = d };
		
		if (crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi))
		{
			makeFinite(aDD);
			makeFinite(bDD);
			zeroNaN(cDD);
			zeroNaN(dDD);
			recalc = 1;
		}
		
		if (crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi))
		{
			makeFinite(cDD);
			makeFinite(dDD);
			zeroNaN(aDD);
			zeroNaN(bDD);
			recalc = 1;
		}
		
		if (!recalc)
		{
			DD acDD = { .ld = ac };
			DD bdDD = { .ld = bd };
			DD adDD = { .ld = ad };
			DD bcDD = { .ld = bc };
			
			if (crt_isinf(acDD.s.hi) || crt_isinf(bdDD.s.hi) ||
                            crt_isinf(adDD.s.hi) || crt_isinf(bcDD.s.hi))
			{
				zeroNaN(aDD);
				zeroNaN(bDD);
				zeroNaN(cDD);
				zeroNaN(dDD);
				recalc = 1;
			}
		}
		
		if (recalc)
		{
			real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi);
			real.s.lo = 0.0;
			imag.s.hi = CRT_INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi);
			imag.s.lo = 0.0;
		}
	}
	
	long double _Complex z;
	__real__ z = real.ld;
	__imag__ z = imag.ld;
	
	return z;
}