blob: ae59d052834e2f985815328bba6f602bff59e6dc [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"
Daniel Dunbar86030242011-11-16 07:33:00 +000018#include "int_math.h"
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019#include <math.h>
Daniel Dunbarb3a69012009-06-26 16:47:03 +000020
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000021/* Returns: the product of a + ib and c + id */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000022
23long double _Complex
24__mulxc3(long double __a, long double __b, long double __c, long double __d)
25{
26 long double __ac = __a * __c;
27 long double __bd = __b * __d;
28 long double __ad = __a * __d;
29 long double __bc = __b * __c;
30 long double _Complex z;
31 __real__ z = __ac - __bd;
32 __imag__ z = __ad + __bc;
Daniel Dunbar86030242011-11-16 07:33:00 +000033 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000034 {
35 int __recalc = 0;
Daniel Dunbar86030242011-11-16 07:33:00 +000036 if (crt_isinf(__a) || crt_isinf(__b))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000037 {
Daniel Dunbar86030242011-11-16 07:33:00 +000038 __a = copysignl(crt_isinf(__a) ? 1 : 0, __a);
39 __b = copysignl(crt_isinf(__b) ? 1 : 0, __b);
40 if (crt_isnan(__c))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000041 __c = copysignl(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000042 if (crt_isnan(__d))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000043 __d = copysignl(0, __d);
44 __recalc = 1;
45 }
Daniel Dunbar86030242011-11-16 07:33:00 +000046 if (crt_isinf(__c) || crt_isinf(__d))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000047 {
Daniel Dunbar86030242011-11-16 07:33:00 +000048 __c = copysignl(crt_isinf(__c) ? 1 : 0, __c);
49 __d = copysignl(crt_isinf(__d) ? 1 : 0, __d);
50 if (crt_isnan(__a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000051 __a = copysignl(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000052 if (crt_isnan(__b))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000053 __b = copysignl(0, __b);
54 __recalc = 1;
55 }
Daniel Dunbar86030242011-11-16 07:33:00 +000056 if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
57 crt_isinf(__ad) || crt_isinf(__bc)))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000058 {
Daniel Dunbar86030242011-11-16 07:33:00 +000059 if (crt_isnan(__a))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000060 __a = copysignl(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000061 if (crt_isnan(__b))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000062 __b = copysignl(0, __b);
Daniel Dunbar86030242011-11-16 07:33:00 +000063 if (crt_isnan(__c))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000064 __c = copysignl(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000065 if (crt_isnan(__d))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000066 __d = copysignl(0, __d);
67 __recalc = 1;
68 }
69 if (__recalc)
70 {
71 __real__ z = INFINITY * (__a * __c - __b * __d);
72 __imag__ z = INFINITY * (__a * __d + __b * __c);
73 }
74 }
75 return z;
76}
77
78#endif