blob: 6d433fbc45f9f30cc7d5cd5167ac2f1f536fed44 [file] [log] [blame]
Edward O'Callaghan37a6a452009-08-07 20:30:09 +00001/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
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'Callaghan37a6a452009-08-07 20:30:09 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __mulsc3 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#include "int_lib.h"
Daniel Dunbar86030242011-11-16 07:33:00 +000016#include "int_math.h"
Daniel Dunbarb3a69012009-06-26 16:47:03 +000017
Edward O'Callaghan37a6a452009-08-07 20:30:09 +000018/* Returns: the product of a + ib and c + id */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019
20float _Complex
21__mulsc3(float __a, float __b, float __c, float __d)
22{
23 float __ac = __a * __c;
24 float __bd = __b * __d;
25 float __ad = __a * __d;
26 float __bc = __b * __c;
27 float _Complex z;
28 __real__ z = __ac - __bd;
29 __imag__ z = __ad + __bc;
Daniel Dunbar86030242011-11-16 07:33:00 +000030 if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000031 {
32 int __recalc = 0;
Daniel Dunbar86030242011-11-16 07:33:00 +000033 if (crt_isinf(__a) || crt_isinf(__b))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000034 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000035 __a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
36 __b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
Daniel Dunbar86030242011-11-16 07:33:00 +000037 if (crt_isnan(__c))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000038 __c = crt_copysignf(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000039 if (crt_isnan(__d))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000040 __d = crt_copysignf(0, __d);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000041 __recalc = 1;
42 }
Daniel Dunbar86030242011-11-16 07:33:00 +000043 if (crt_isinf(__c) || crt_isinf(__d))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000044 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000045 __c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
46 __d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
Daniel Dunbar86030242011-11-16 07:33:00 +000047 if (crt_isnan(__a))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000048 __a = crt_copysignf(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000049 if (crt_isnan(__b))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000050 __b = crt_copysignf(0, __b);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000051 __recalc = 1;
52 }
Daniel Dunbar86030242011-11-16 07:33:00 +000053 if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
54 crt_isinf(__ad) || crt_isinf(__bc)))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000055 {
Daniel Dunbar86030242011-11-16 07:33:00 +000056 if (crt_isnan(__a))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000057 __a = crt_copysignf(0, __a);
Daniel Dunbar86030242011-11-16 07:33:00 +000058 if (crt_isnan(__b))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000059 __b = crt_copysignf(0, __b);
Daniel Dunbar86030242011-11-16 07:33:00 +000060 if (crt_isnan(__c))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000061 __c = crt_copysignf(0, __c);
Daniel Dunbar86030242011-11-16 07:33:00 +000062 if (crt_isnan(__d))
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000063 __d = crt_copysignf(0, __d);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000064 __recalc = 1;
65 }
66 if (__recalc)
67 {
Daniel Dunbarc25c6d12011-11-16 07:33:06 +000068 __real__ z = CRT_INFINITY * (__a * __c - __b * __d);
69 __imag__ z = CRT_INFINITY * (__a * __d + __b * __c);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000070 }
71 }
72 return z;
73}