2009-08-08 04:30:09 +08:00
|
|
|
/* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-08 04:30:09 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __mulsc3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
2011-11-16 15:33:00 +08:00
|
|
|
#include "int_math.h"
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* Returns: the product of a + ib and c + id */
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
float _Complex
|
|
|
|
__mulsc3(float __a, float __b, float __c, float __d)
|
|
|
|
{
|
|
|
|
float __ac = __a * __c;
|
|
|
|
float __bd = __b * __d;
|
|
|
|
float __ad = __a * __d;
|
|
|
|
float __bc = __b * __c;
|
|
|
|
float _Complex z;
|
|
|
|
__real__ z = __ac - __bd;
|
|
|
|
__imag__ z = __ad + __bc;
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__real__ z) && crt_isnan(__imag__ z))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
int __recalc = 0;
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(__a) || crt_isinf(__b))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(crt_isinf(__a) ? 1 : 0, __a);
|
|
|
|
__b = crt_copysignf(crt_isinf(__b) ? 1 : 0, __b);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__c))
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(0, __c);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__d))
|
2011-11-16 15:33:06 +08:00
|
|
|
__d = crt_copysignf(0, __d);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(__c) || crt_isinf(__d))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(crt_isinf(__c) ? 1 : 0, __c);
|
|
|
|
__d = crt_copysignf(crt_isinf(__d) ? 1 : 0, __d);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__a))
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(0, __a);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__b))
|
2011-11-16 15:33:06 +08:00
|
|
|
__b = crt_copysignf(0, __b);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
2011-11-16 15:33:00 +08:00
|
|
|
if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
|
|
|
|
crt_isinf(__ad) || crt_isinf(__bc)))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__a))
|
2011-11-16 15:33:06 +08:00
|
|
|
__a = crt_copysignf(0, __a);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__b))
|
2011-11-16 15:33:06 +08:00
|
|
|
__b = crt_copysignf(0, __b);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__c))
|
2011-11-16 15:33:06 +08:00
|
|
|
__c = crt_copysignf(0, __c);
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(__d))
|
2011-11-16 15:33:06 +08:00
|
|
|
__d = crt_copysignf(0, __d);
|
2009-06-27 00:47:03 +08:00
|
|
|
__recalc = 1;
|
|
|
|
}
|
|
|
|
if (__recalc)
|
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
__real__ z = CRT_INFINITY * (__a * __c - __b * __d);
|
|
|
|
__imag__ z = CRT_INFINITY * (__a * __d + __b * __c);
|
2009-06-27 00:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return z;
|
|
|
|
}
|