blob: a7f2355410cd989d8198915211e864b3395596a6 [file] [log] [blame]
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00001/* ===-- mulxc3.c - Implement __mulxc3 -------------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __mulxc3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#if !_ARCH_PPC
16
17#include "int_lib.h"
18#include <math.h>
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000020/* Returns: the product of a + ib and c + id */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
22long double _Complex
23__mulxc3(long double __a, long double __b, long double __c, long double __d)
24{
25 long double __ac = __a * __c;
26 long double __bd = __b * __d;
27 long double __ad = __a * __d;
28 long double __bc = __b * __c;
29 long double _Complex z;
30 __real__ z = __ac - __bd;
31 __imag__ z = __ad + __bc;
32 if (isnan(__real__ z) && isnan(__imag__ z))
33 {
34 int __recalc = 0;
35 if (isinf(__a) || isinf(__b))
36 {
37 __a = copysignl(isinf(__a) ? 1 : 0, __a);
38 __b = copysignl(isinf(__b) ? 1 : 0, __b);
39 if (isnan(__c))
40 __c = copysignl(0, __c);
41 if (isnan(__d))
42 __d = copysignl(0, __d);
43 __recalc = 1;
44 }
45 if (isinf(__c) || isinf(__d))
46 {
47 __c = copysignl(isinf(__c) ? 1 : 0, __c);
48 __d = copysignl(isinf(__d) ? 1 : 0, __d);
49 if (isnan(__a))
50 __a = copysignl(0, __a);
51 if (isnan(__b))
52 __b = copysignl(0, __b);
53 __recalc = 1;
54 }
55 if (!__recalc && (isinf(__ac) || isinf(__bd) ||
56 isinf(__ad) || isinf(__bc)))
57 {
58 if (isnan(__a))
59 __a = copysignl(0, __a);
60 if (isnan(__b))
61 __b = copysignl(0, __b);
62 if (isnan(__c))
63 __c = copysignl(0, __c);
64 if (isnan(__d))
65 __d = copysignl(0, __d);
66 __recalc = 1;
67 }
68 if (__recalc)
69 {
70 __real__ z = INFINITY * (__a * __c - __b * __d);
71 __imag__ z = INFINITY * (__a * __d + __b * __c);
72 }
73 }
74 return z;
75}
76
77#endif