1 //===-- multc3.c - Implement __multc3 -------------------------------------===//
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 __multc3 for the compiler_rt library.
11 //===----------------------------------------------------------------------===//
16 // Returns: the product of a + ib and c + id
18 COMPILER_RT_ABI long double _Complex __multc3(long double a, long double b,
19 long double c, long double d) {
20 long double ac = a * c;
21 long double bd = b * d;
22 long double ad = a * d;
23 long double bc = b * c;
24 long double _Complex z;
27 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z)) {
29 if (crt_isinf(a) || crt_isinf(b)) {
30 a = crt_copysignl(crt_isinf(a) ? 1 : 0, a);
31 b = crt_copysignl(crt_isinf(b) ? 1 : 0, b);
33 c = crt_copysignl(0, c);
35 d = crt_copysignl(0, d);
38 if (crt_isinf(c) || crt_isinf(d)) {
39 c = crt_copysignl(crt_isinf(c) ? 1 : 0, c);
40 d = crt_copysignl(crt_isinf(d) ? 1 : 0, d);
42 a = crt_copysignl(0, a);
44 b = crt_copysignl(0, b);
48 (crt_isinf(ac) || crt_isinf(bd) || crt_isinf(ad) || crt_isinf(bc))) {
50 a = crt_copysignl(0, a);
52 b = crt_copysignl(0, b);
54 c = crt_copysignl(0, c);
56 d = crt_copysignl(0, d);
60 __real__ z = CRT_INFINITY * (a * c - b * d);
61 __imag__ z = CRT_INFINITY * (a * d + b * c);