Home | History | Annotate | Download | only in ppc
      1 /* This file is distributed under the University of Illinois Open Source
      2  * License. See LICENSE.TXT for details.
      3  */
      4 
      5 #include "DD.h"
      6 #include "../int_math.h"
      7 
      8 #define makeFinite(x) { \
      9     (x).s.hi = crt_copysign(crt_isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \
     10     (x).s.lo = 0.0;                                                     \
     11   }
     12 
     13 #define zeroNaN(x) { \
     14     if (crt_isnan((x).s.hi)) {                                          \
     15       (x).s.hi = crt_copysign(0.0, (x).s.hi);                     \
     16       (x).s.lo = 0.0;                                                   \
     17     }                                                                   \
     18   }
     19 
     20 long double __gcc_qadd(long double, long double);
     21 long double __gcc_qsub(long double, long double);
     22 long double __gcc_qmul(long double, long double);
     23 
     24 long double _Complex
     25 __multc3(long double a, long double b, long double c, long double d)
     26 {
     27 	long double ac = __gcc_qmul(a,c);
     28 	long double bd = __gcc_qmul(b,d);
     29 	long double ad = __gcc_qmul(a,d);
     30 	long double bc = __gcc_qmul(b,c);
     31 
     32 	DD real = { .ld = __gcc_qsub(ac,bd) };
     33 	DD imag = { .ld = __gcc_qadd(ad,bc) };
     34 
     35 	if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi))
     36 	{
     37 		int recalc = 0;
     38 
     39 		DD aDD = { .ld = a };
     40 		DD bDD = { .ld = b };
     41 		DD cDD = { .ld = c };
     42 		DD dDD = { .ld = d };
     43 
     44 		if (crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi))
     45 		{
     46 			makeFinite(aDD);
     47 			makeFinite(bDD);
     48 			zeroNaN(cDD);
     49 			zeroNaN(dDD);
     50 			recalc = 1;
     51 		}
     52 
     53 		if (crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi))
     54 		{
     55 			makeFinite(cDD);
     56 			makeFinite(dDD);
     57 			zeroNaN(aDD);
     58 			zeroNaN(bDD);
     59 			recalc = 1;
     60 		}
     61 
     62 		if (!recalc)
     63 		{
     64 			DD acDD = { .ld = ac };
     65 			DD bdDD = { .ld = bd };
     66 			DD adDD = { .ld = ad };
     67 			DD bcDD = { .ld = bc };
     68 
     69 			if (crt_isinf(acDD.s.hi) || crt_isinf(bdDD.s.hi) ||
     70                             crt_isinf(adDD.s.hi) || crt_isinf(bcDD.s.hi))
     71 			{
     72 				zeroNaN(aDD);
     73 				zeroNaN(bDD);
     74 				zeroNaN(cDD);
     75 				zeroNaN(dDD);
     76 				recalc = 1;
     77 			}
     78 		}
     79 
     80 		if (recalc)
     81 		{
     82 			real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi);
     83 			real.s.lo = 0.0;
     84 			imag.s.hi = CRT_INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi);
     85 			imag.s.lo = 0.0;
     86 		}
     87 	}
     88 
     89 	long double _Complex z;
     90 	__real__ z = real.ld;
     91 	__imag__ z = imag.ld;
     92 
     93 	return z;
     94 }
     95