1 /* ===-- multc3.c - Implement __multc3 -------------------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file implements __multc3 for the compiler_rt library.
12 * ===----------------------------------------------------------------------===
18 /* Returns: the product of a + ib and c + id */
20 COMPILER_RT_ABI long double _Complex
21 __multc3(long double a, long double b, long double c, long double d)
23 long double ac = a * c;
24 long double bd = b * d;
25 long double ad = a * d;
26 long double bc = b * c;
27 long double _Complex z;
30 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) {
32 if (crt_isinf(a) || crt_isinf(b)) {
33 a = crt_copysignl(crt_isinf(a) ? 1 : 0, a);
34 b = crt_copysignl(crt_isinf(b) ? 1 : 0, b);
36 c = crt_copysignl(0, c);
38 d = crt_copysignl(0, d);
41 if (crt_isinf(c) || crt_isinf(d)) {
42 c = crt_copysignl(crt_isinf(c) ? 1 : 0, c);
43 d = crt_copysignl(crt_isinf(d) ? 1 : 0, d);
45 a = crt_copysignl(0, a);
47 b = crt_copysignl(0, b);
50 if (!recalc && (crt_isinf(ac) || crt_isinf(bd) ||
51 crt_isinf(ad) || crt_isinf(bc))) {
53 a = crt_copysignl(0, a);
55 b = crt_copysignl(0, b);
57 c = crt_copysignl(0, c);
59 d = crt_copysignl(0, d);
63 __real__ z = CRT_INFINITY * (a * c - b * d);
64 __imag__ z = CRT_INFINITY * (a * d + b * c);