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 _Complex
__multc3(long double a,long double b,long double c,long double d)21 __multc3(long double a, long double b, long double c, long double d)
22 {
23 long double ac = __gcc_qmul(a,c);
24 long double bd = __gcc_qmul(b,d);
25 long double ad = __gcc_qmul(a,d);
26 long double bc = __gcc_qmul(b,c);
27
28 DD real = { .ld = __gcc_qsub(ac,bd) };
29 DD imag = { .ld = __gcc_qadd(ad,bc) };
30
31 if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi))
32 {
33 int recalc = 0;
34
35 DD aDD = { .ld = a };
36 DD bDD = { .ld = b };
37 DD cDD = { .ld = c };
38 DD dDD = { .ld = d };
39
40 if (crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi))
41 {
42 makeFinite(aDD);
43 makeFinite(bDD);
44 zeroNaN(cDD);
45 zeroNaN(dDD);
46 recalc = 1;
47 }
48
49 if (crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi))
50 {
51 makeFinite(cDD);
52 makeFinite(dDD);
53 zeroNaN(aDD);
54 zeroNaN(bDD);
55 recalc = 1;
56 }
57
58 if (!recalc)
59 {
60 DD acDD = { .ld = ac };
61 DD bdDD = { .ld = bd };
62 DD adDD = { .ld = ad };
63 DD bcDD = { .ld = bc };
64
65 if (crt_isinf(acDD.s.hi) || crt_isinf(bdDD.s.hi) ||
66 crt_isinf(adDD.s.hi) || crt_isinf(bcDD.s.hi))
67 {
68 zeroNaN(aDD);
69 zeroNaN(bDD);
70 zeroNaN(cDD);
71 zeroNaN(dDD);
72 recalc = 1;
73 }
74 }
75
76 if (recalc)
77 {
78 real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi);
79 real.s.lo = 0.0;
80 imag.s.hi = CRT_INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi);
81 imag.s.lo = 0.0;
82 }
83 }
84
85 long double _Complex z;
86 __real__ z = real.ld;
87 __imag__ z = imag.ld;
88
89 return z;
90 }
91