1 //===-- muldc3.c - Implement __muldc3 -------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements __muldc3 for the compiler_rt library.
11 //===----------------------------------------------------------------------===//
16 // Returns: the product of a + ib and c + id
18 COMPILER_RT_ABI Dcomplex
__muldc3(double __a
, double __b
, double __c
,
20 double __ac
= __a
* __c
;
21 double __bd
= __b
* __d
;
22 double __ad
= __a
* __d
;
23 double __bc
= __b
* __c
;
25 COMPLEX_REAL(z
) = __ac
- __bd
;
26 COMPLEX_IMAGINARY(z
) = __ad
+ __bc
;
27 if (crt_isnan(COMPLEX_REAL(z
)) && crt_isnan(COMPLEX_IMAGINARY(z
))) {
29 if (crt_isinf(__a
) || crt_isinf(__b
)) {
30 __a
= crt_copysign(crt_isinf(__a
) ? 1 : 0, __a
);
31 __b
= crt_copysign(crt_isinf(__b
) ? 1 : 0, __b
);
33 __c
= crt_copysign(0, __c
);
35 __d
= crt_copysign(0, __d
);
38 if (crt_isinf(__c
) || crt_isinf(__d
)) {
39 __c
= crt_copysign(crt_isinf(__c
) ? 1 : 0, __c
);
40 __d
= crt_copysign(crt_isinf(__d
) ? 1 : 0, __d
);
42 __a
= crt_copysign(0, __a
);
44 __b
= crt_copysign(0, __b
);
47 if (!__recalc
&& (crt_isinf(__ac
) || crt_isinf(__bd
) || crt_isinf(__ad
) ||
50 __a
= crt_copysign(0, __a
);
52 __b
= crt_copysign(0, __b
);
54 __c
= crt_copysign(0, __c
);
56 __d
= crt_copysign(0, __d
);
60 COMPLEX_REAL(z
) = CRT_INFINITY
* (__a
* __c
- __b
* __d
);
61 COMPLEX_IMAGINARY(z
) = CRT_INFINITY
* (__a
* __d
+ __b
* __c
);