1 /* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
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 __muldc3 for the compiler_rt library.
12 * ===----------------------------------------------------------------------===
19 /* Returns: the product of a + ib and c + id */
22 __muldc3(double __a, double __b, double __c, double __d)
24 double __ac = __a * __c;
25 double __bd = __b * __d;
26 double __ad = __a * __d;
27 double __bc = __b * __c;
29 __real__ z = __ac - __bd;
30 __imag__ z = __ad + __bc;
31 if (isnan(__real__ z) && isnan(__imag__ z))
34 if (isinf(__a) || isinf(__b))
36 __a = copysign(isinf(__a) ? 1 : 0, __a);
37 __b = copysign(isinf(__b) ? 1 : 0, __b);
39 __c = copysign(0, __c);
41 __d = copysign(0, __d);
44 if (isinf(__c) || isinf(__d))
46 __c = copysign(isinf(__c) ? 1 : 0, __c);
47 __d = copysign(isinf(__d) ? 1 : 0, __d);
49 __a = copysign(0, __a);
51 __b = copysign(0, __b);
54 if (!__recalc && (isinf(__ac) || isinf(__bd) ||
55 isinf(__ad) || isinf(__bc)))
58 __a = copysign(0, __a);
60 __b = copysign(0, __b);
62 __c = copysign(0, __c);
64 __d = copysign(0, __d);
69 __real__ z = INFINITY * (__a * __c - __b * __d);
70 __imag__ z = INFINITY * (__a * __d + __b * __c);