blob: b945e8e382741f3ba0c33f7c862ce2ba1e6f4475 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- muldc3.c - Implement __muldc3 -------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __muldc3 for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15#include <math.h>
16#include <complex.h>
17
18// Returns: the product of a + ib and c + id
19
20double _Complex
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;
27 double _Complex z;
28 __real__ z = __ac - __bd;
29 __imag__ z = __ad + __bc;
30 if (isnan(__real__ z) && isnan(__imag__ z))
31 {
32 int __recalc = 0;
33 if (isinf(__a) || isinf(__b))
34 {
35 __a = copysign(isinf(__a) ? 1 : 0, __a);
36 __b = copysign(isinf(__b) ? 1 : 0, __b);
37 if (isnan(__c))
38 __c = copysign(0, __c);
39 if (isnan(__d))
40 __d = copysign(0, __d);
41 __recalc = 1;
42 }
43 if (isinf(__c) || isinf(__d))
44 {
45 __c = copysign(isinf(__c) ? 1 : 0, __c);
46 __d = copysign(isinf(__d) ? 1 : 0, __d);
47 if (isnan(__a))
48 __a = copysign(0, __a);
49 if (isnan(__b))
50 __b = copysign(0, __b);
51 __recalc = 1;
52 }
53 if (!__recalc && (isinf(__ac) || isinf(__bd) ||
54 isinf(__ad) || isinf(__bc)))
55 {
56 if (isnan(__a))
57 __a = copysign(0, __a);
58 if (isnan(__b))
59 __b = copysign(0, __b);
60 if (isnan(__c))
61 __c = copysign(0, __c);
62 if (isnan(__d))
63 __d = copysign(0, __d);
64 __recalc = 1;
65 }
66 if (__recalc)
67 {
68 __real__ z = INFINITY * (__a * __c - __b * __d);
69 __imag__ z = INFINITY * (__a * __d + __b * __c);
70 }
71 }
72 return z;
73}