2009-08-08 12:43:56 +08:00
|
|
|
/* This file is distributed under the University of Illinois Open Source
|
|
|
|
* License. See LICENSE.TXT for details.
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#include "DD.h"
|
2011-11-16 15:33:00 +08:00
|
|
|
#include "../int_math.h"
|
2009-08-08 12:43:56 +08:00
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
#define makeFinite(x) { \
|
2011-11-16 15:33:06 +08:00
|
|
|
(x).s.hi = crt_copysign(crt_isinf((x).s.hi) ? 1.0 : 0.0, (x).s.hi); \
|
2011-11-16 15:33:00 +08:00
|
|
|
(x).s.lo = 0.0; \
|
|
|
|
}
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
#define zeroNaN() { \
|
|
|
|
if (crt_isnan((x).s.hi)) { \
|
2011-11-16 15:33:06 +08:00
|
|
|
(x).s.hi = crt_copysign(0.0, (x).s.hi); \
|
2011-11-16 15:33:00 +08:00
|
|
|
(x).s.lo = 0.0; \
|
|
|
|
} \
|
|
|
|
}
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
long double __gcc_qadd(long double, long double);
|
|
|
|
long double __gcc_qsub(long double, long double);
|
|
|
|
long double __gcc_qmul(long double, long double);
|
|
|
|
|
|
|
|
long double _Complex
|
|
|
|
__multc3(long double a, long double b, long double c, long double d)
|
|
|
|
{
|
|
|
|
long double ac = __gcc_qmul(a,c);
|
|
|
|
long double bd = __gcc_qmul(b,d);
|
|
|
|
long double ad = __gcc_qmul(a,d);
|
|
|
|
long double bc = __gcc_qmul(b,c);
|
|
|
|
|
|
|
|
DD real = { .ld = __gcc_qsub(ac,bd) };
|
|
|
|
DD imag = { .ld = __gcc_qadd(ad,bc) };
|
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isnan(real.s.hi) && crt_isnan(imag.s.hi))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
int recalc = 0;
|
|
|
|
|
|
|
|
DD aDD = { .ld = a };
|
|
|
|
DD bDD = { .ld = b };
|
|
|
|
DD cDD = { .ld = c };
|
|
|
|
DD dDD = { .ld = d };
|
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(aDD.s.hi) || crt_isinf(bDD.s.hi))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
makeFinite(aDD);
|
|
|
|
makeFinite(bDD);
|
|
|
|
zeroNaN(cDD);
|
|
|
|
zeroNaN(dDD);
|
|
|
|
recalc = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(cDD.s.hi) || crt_isinf(dDD.s.hi))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
makeFinite(cDD);
|
|
|
|
makeFinite(dDD);
|
|
|
|
zeroNaN(aDD);
|
|
|
|
zeroNaN(bDD);
|
|
|
|
recalc = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!recalc)
|
|
|
|
{
|
|
|
|
DD acDD = { .ld = ac };
|
|
|
|
DD bdDD = { .ld = bd };
|
|
|
|
DD adDD = { .ld = ad };
|
|
|
|
DD bcDD = { .ld = bc };
|
|
|
|
|
2011-11-16 15:33:00 +08:00
|
|
|
if (crt_isinf(acDD.s.hi) || crt_isinf(bdDD.s.hi) ||
|
|
|
|
crt_isinf(adDD.s.hi) || crt_isinf(bcDD.s.hi))
|
2009-06-27 00:47:03 +08:00
|
|
|
{
|
|
|
|
zeroNaN(aDD);
|
|
|
|
zeroNaN(bDD);
|
|
|
|
zeroNaN(cDD);
|
|
|
|
zeroNaN(dDD);
|
|
|
|
recalc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recalc)
|
|
|
|
{
|
2011-11-16 15:33:06 +08:00
|
|
|
real.s.hi = CRT_INFINITY * (aDD.s.hi*cDD.s.hi - bDD.s.hi*dDD.s.hi);
|
2009-08-10 02:41:02 +08:00
|
|
|
real.s.lo = 0.0;
|
2011-11-16 15:33:06 +08:00
|
|
|
imag.s.hi = CRT_INFINITY * (aDD.s.hi*dDD.s.hi + bDD.s.hi*cDD.s.hi);
|
2009-08-10 02:41:02 +08:00
|
|
|
imag.s.lo = 0.0;
|
2009-06-27 00:47:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long double _Complex z;
|
|
|
|
__real__ z = real.ld;
|
|
|
|
__imag__ z = imag.ld;
|
|
|
|
|
|
|
|
return z;
|
|
|
|
}
|