]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/lib/builtins/muldc3.c
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / lib / builtins / muldc3.c
CommitLineData
1a4d82fc
JJ
1/* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
7 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __muldc3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
14
15#include "int_lib.h"
16#include "int_math.h"
17
18/* Returns: the product of a + ib and c + id */
19
92a42be0 20COMPILER_RT_ABI Dcomplex
1a4d82fc
JJ
21__muldc3(double __a, double __b, double __c, double __d)
22{
23 double __ac = __a * __c;
24 double __bd = __b * __d;
25 double __ad = __a * __d;
26 double __bc = __b * __c;
92a42be0
SL
27 Dcomplex z;
28 COMPLEX_REAL(z) = __ac - __bd;
29 COMPLEX_IMAGINARY(z) = __ad + __bc;
30 if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
1a4d82fc
JJ
31 {
32 int __recalc = 0;
33 if (crt_isinf(__a) || crt_isinf(__b))
34 {
35 __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
36 __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
37 if (crt_isnan(__c))
38 __c = crt_copysign(0, __c);
39 if (crt_isnan(__d))
40 __d = crt_copysign(0, __d);
41 __recalc = 1;
42 }
43 if (crt_isinf(__c) || crt_isinf(__d))
44 {
45 __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
46 __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
47 if (crt_isnan(__a))
48 __a = crt_copysign(0, __a);
49 if (crt_isnan(__b))
50 __b = crt_copysign(0, __b);
51 __recalc = 1;
52 }
53 if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
54 crt_isinf(__ad) || crt_isinf(__bc)))
55 {
56 if (crt_isnan(__a))
57 __a = crt_copysign(0, __a);
58 if (crt_isnan(__b))
59 __b = crt_copysign(0, __b);
60 if (crt_isnan(__c))
61 __c = crt_copysign(0, __c);
62 if (crt_isnan(__d))
63 __d = crt_copysign(0, __d);
64 __recalc = 1;
65 }
66 if (__recalc)
67 {
92a42be0
SL
68 COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
69 COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
1a4d82fc
JJ
70 }
71 }
72 return z;
73}