arb/fmpr/mul.c

86 lines
2.6 KiB
C
Raw Normal View History

/*=============================================================================
This file is part of ARB.
ARB is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ARB is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ARB; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
=============================================================================*/
/******************************************************************************
Copyright (C) 2012, 2014 Fredrik Johansson
******************************************************************************/
#include "fmpr.h"
long
2015-11-05 18:03:08 +00:00
fmpr_mul(fmpr_t z, const fmpr_t x, const fmpr_t y, slong prec, fmpr_rnd_t rnd)
{
fmpz xv, yv;
2013-01-03 15:11:55 +01:00
if (fmpr_is_special(x) || fmpr_is_special(y))
{
if (fmpr_is_zero(x) && fmpr_is_finite(y))
2013-01-03 15:11:55 +01:00
{
fmpr_zero(z);
2013-01-03 15:11:55 +01:00
}
else if (fmpr_is_zero(y) && fmpr_is_finite(x))
2013-01-03 15:11:55 +01:00
{
fmpr_zero(z);
2013-01-03 15:11:55 +01:00
}
else if ((fmpr_is_inf(x) && (fmpr_is_inf(y) || !fmpr_is_special(y))) ||
(fmpr_is_inf(y) && !fmpr_is_special(x)))
2013-01-03 15:11:55 +01:00
{
if (fmpr_sgn(x) == fmpr_sgn(y))
fmpr_pos_inf(z);
else
fmpr_neg_inf(z);
2013-01-03 15:11:55 +01:00
}
else
{
fmpr_nan(z);
}
2013-01-03 15:11:55 +01:00
return FMPR_RESULT_EXACT;
}
2013-01-03 15:11:55 +01:00
xv = *fmpr_manref(x);
yv = *fmpr_manref(y);
2013-01-03 15:11:55 +01:00
if (!COEFF_IS_MPZ(xv) && !COEFF_IS_MPZ(yv))
{
2014-03-08 17:52:25 +01:00
return _fmpr_mul_1x1(z, FLINT_ABS(xv), fmpr_expref(x),
FLINT_ABS(yv), fmpr_expref(y), (xv ^ yv) < 0, prec, rnd);
}
else
{
2015-11-05 18:03:08 +00:00
slong xn, yn;
int xsign, ysign;
mp_limb_t xtmp, ytmp;
mp_ptr xptr, yptr;
FMPZ_GET_MPN_READONLY(xsign, xn, xptr, xtmp, xv)
FMPZ_GET_MPN_READONLY(ysign, yn, yptr, ytmp, yv)
if (xn >= yn)
2014-03-08 17:52:25 +01:00
return _fmpr_mul_mpn(z, xptr, xn, fmpr_expref(x),
yptr, yn, fmpr_expref(y), xsign ^ ysign, prec, rnd);
else
2014-03-08 17:52:25 +01:00
return _fmpr_mul_mpn(z, yptr, yn, fmpr_expref(y),
xptr, xn, fmpr_expref(x), ysign ^ xsign, prec, rnd);
2013-01-03 15:11:55 +01:00
}
2012-09-06 13:18:02 +02:00
}