本文整理汇总了C++中MPFR_SET_EXP函数的典型用法代码示例。如果您正苦于以下问题:C++ MPFR_SET_EXP函数的具体用法?C++ MPFR_SET_EXP怎么用?C++ MPFR_SET_EXP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MPFR_SET_EXP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mpfr_div_2ui
int
mpfr_div_2ui (mpfr_ptr y, mpfr_srcptr x, unsigned long n, mpfr_rnd_t rnd_mode)
{
int inexact;
MPFR_LOG_FUNC (("x[%#R]=%R n=%lu rnd=%d", x, x, n, rnd_mode),
("y[%#R]=%R inexact=%d", y, y, inexact));
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
return mpfr_set (y, x, rnd_mode);
else
{
mpfr_exp_t exp = MPFR_GET_EXP (x);
mpfr_uexp_t diffexp;
MPFR_SETRAW (inexact, y, x, exp, rnd_mode);
diffexp = (mpfr_uexp_t) exp - (mpfr_uexp_t) (__gmpfr_emin - 1);
if (MPFR_UNLIKELY (n >= diffexp)) /* exp - n <= emin - 1 */
{
if (rnd_mode == MPFR_RNDN &&
(n > diffexp || (inexact >= 0 && mpfr_powerof2_raw (y))))
rnd_mode = MPFR_RNDZ;
return mpfr_underflow (y, rnd_mode, MPFR_SIGN (y));
}
/* exp - n >= emin (no underflow, no integer overflow) */
while (n > LONG_MAX)
{
n -= LONG_MAX;
exp -= LONG_MAX; /* note: signed values */
}
MPFR_SET_EXP (y, exp - (long) n);
}
MPFR_RET (inexact);
}
示例2: mpfr_ui_div
int
mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
{
mpfr_t uu;
mp_limb_t up[1];
unsigned long cnt;
MPFR_LOG_FUNC
(("u=%lu x[%Pu]=%.*Rg rnd=%d",
u, mpfr_get_prec(x), mpfr_log_prec, x, rnd_mode),
("y[%Pu]=%.*Rg", mpfr_get_prec(y), mpfr_log_prec, y));
if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
{
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
else if (MPFR_IS_INF(x)) /* u/Inf = 0 */
{
MPFR_SET_ZERO(y);
MPFR_SET_SAME_SIGN(y,x);
MPFR_RET(0);
}
else /* u / 0 */
{
MPFR_ASSERTD(MPFR_IS_ZERO(x));
if (u)
{
/* u > 0, so y = sign(x) * Inf */
MPFR_SET_SAME_SIGN(y, x);
MPFR_SET_INF(y);
mpfr_set_divby0 ();
MPFR_RET(0);
}
else
{
/* 0 / 0 */
MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
}
}
else if (MPFR_LIKELY(u != 0))
{
MPFR_TMP_INIT1(up, uu, GMP_NUMB_BITS);
MPFR_ASSERTN(u == (mp_limb_t) u);
count_leading_zeros(cnt, (mp_limb_t) u);
up[0] = (mp_limb_t) u << cnt;
MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
return mpfr_div (y, uu, x, rnd_mode);
}
else /* u = 0, and x != 0 */
{
MPFR_SET_ZERO(y); /* if u=0, then set y to 0 */
MPFR_SET_SAME_SIGN(y, x); /* u considered as +0: sign(+0/x) = sign(x) */
MPFR_RET(0);
}
}
示例3: mpfr_sqrt_ui
int
mpfr_sqrt_ui (mpfr_ptr r, unsigned long u, mpfr_rnd_t rnd_mode)
{
if (u)
{
mpfr_t uu;
mp_limb_t up[1];
unsigned long cnt;
int inex;
MPFR_SAVE_EXPO_DECL (expo);
MPFR_TMP_INIT1 (up, uu, GMP_NUMB_BITS);
MPFR_ASSERTN (u == (mp_limb_t) u);
count_leading_zeros (cnt, (mp_limb_t) u);
*up = (mp_limb_t) u << cnt;
MPFR_SAVE_EXPO_MARK (expo);
MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
inex = mpfr_sqrt(r, uu, rnd_mode);
MPFR_SAVE_EXPO_FREE (expo);
return mpfr_check_range(r, inex, rnd_mode);
}
else /* sqrt(0) = 0 */
{
MPFR_SET_ZERO(r);
MPFR_SET_POS(r);
MPFR_RET(0);
}
}
示例4: set_z
/*
* Set f to z, choosing the smallest precision for f
* so that z = f*(2^BPML)*zs*2^(RetVal)
*/
static int
set_z (mpfr_ptr f, mpz_srcptr z, mp_size_t *zs)
{
mp_limb_t *p;
mp_size_t s;
int c;
mp_prec_t pf;
MPFR_ASSERTD (mpz_sgn (z) != 0);
/* Remove useless ending 0 */
for (p = PTR (z), s = *zs = ABS (SIZ (z)) ; *p == 0; p++, s--)
MPFR_ASSERTD (s >= 0);
/* Get working precision */
count_leading_zeros (c, p[s-1]);
pf = s * BITS_PER_MP_LIMB - c;
if (pf < MPFR_PREC_MIN)
pf = MPFR_PREC_MIN;
mpfr_init2 (f, pf);
/* Copy Mantissa */
if (MPFR_LIKELY (c))
mpn_lshift (MPFR_MANT (f), p, s, c);
else
MPN_COPY (MPFR_MANT (f), p, s);
MPFR_SET_SIGN (f, mpz_sgn (z));
MPFR_SET_EXP (f, 0);
return -c;
}
示例5: mpfr_frexp
int
mpfr_frexp (mpfr_exp_t *exp, mpfr_ptr y, mpfr_srcptr x, mpfr_rnd_t rnd)
{
int inex;
if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
{
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
MPFR_RET_NAN; /* exp is unspecified */
}
else if (MPFR_IS_INF(x))
{
MPFR_SET_INF(y);
MPFR_SET_SAME_SIGN(y,x);
MPFR_RET(0); /* exp is unspecified */
}
else
{
MPFR_SET_ZERO(y);
MPFR_SET_SAME_SIGN(y,x);
*exp = 0;
MPFR_RET(0);
}
}
inex = mpfr_set (y, x, rnd);
*exp = MPFR_GET_EXP (y);
MPFR_SET_EXP (y, 0);
return mpfr_check_range (y, inex, rnd);
}
示例6: mpfr_sub_ui
int
mpfr_sub_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mp_rnd_t rnd_mode)
{
if (MPFR_LIKELY (u != 0)) /* if u=0, do nothing */
{
mpfr_t uu;
mp_limb_t up[1];
unsigned long cnt;
int inex;
MPFR_SAVE_EXPO_DECL (expo);
MPFR_TMP_INIT1 (up, uu, BITS_PER_MP_LIMB);
MPFR_ASSERTN (u == (mp_limb_t) u);
count_leading_zeros (cnt, (mp_limb_t) u);
*up = (mp_limb_t) u << cnt;
/* Optimization note: Exponent save/restore operations may be
removed if mpfr_sub works even when uu is out-of-range. */
MPFR_SAVE_EXPO_MARK (expo);
MPFR_SET_EXP (uu, BITS_PER_MP_LIMB - cnt);
inex = mpfr_sub (y, x, uu, rnd_mode);
MPFR_SAVE_EXPO_FREE (expo);
return mpfr_check_range (y, inex, rnd_mode);
}
else
return mpfr_set (y, x, rnd_mode);
}
示例7: mpfr_add_ui
int
mpfr_add_ui (mpfr_ptr y, mpfr_srcptr x, unsigned long int u, mpfr_rnd_t rnd_mode)
{
MPFR_LOG_FUNC
(("x[%Pu]=%.*Rg u=%lu rnd=%d",
mpfr_get_prec(x), mpfr_log_prec, x, u, rnd_mode),
("y[%Pu]=%.*Rg", mpfr_get_prec (y), mpfr_log_prec, y));
if (MPFR_LIKELY(u != 0) ) /* if u=0, do nothing */
{
mpfr_t uu;
mp_limb_t up[1];
unsigned long cnt;
int inex;
MPFR_SAVE_EXPO_DECL (expo);
MPFR_TMP_INIT1 (up, uu, GMP_NUMB_BITS);
MPFR_ASSERTD (u == (mp_limb_t) u);
count_leading_zeros(cnt, (mp_limb_t) u);
up[0] = (mp_limb_t) u << cnt;
/* Optimization note: Exponent save/restore operations may be
removed if mpfr_add works even when uu is out-of-range. */
MPFR_SAVE_EXPO_MARK (expo);
MPFR_SET_EXP (uu, GMP_NUMB_BITS - cnt);
inex = mpfr_add(y, x, uu, rnd_mode);
MPFR_SAVE_EXPO_FREE (expo);
return mpfr_check_range(y, inex, rnd_mode);
}
else
/* (unsigned long) 0 is assumed to be a real 0 (unsigned) */
return mpfr_set (y, x, rnd_mode);
}
示例8: mpfr_mul_2si
int
mpfr_mul_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mpfr_rnd_t rnd_mode)
{
int inexact;
MPFR_LOG_FUNC (("x[%#R]=%R n=%ld rnd=%d", x, x, n, rnd_mode),
("y[%#R]=%R inexact=%d", y, y, inexact));
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (x)))
return mpfr_set (y, x, rnd_mode);
else
{
mpfr_exp_t exp = MPFR_GET_EXP (x);
MPFR_SETRAW (inexact, y, x, exp, rnd_mode);
if (MPFR_UNLIKELY( n > 0 && (__gmpfr_emax < MPFR_EMIN_MIN + n ||
exp > __gmpfr_emax - n)))
return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y));
else if (MPFR_UNLIKELY(n < 0 && (__gmpfr_emin > MPFR_EMAX_MAX + n ||
exp < __gmpfr_emin - n)))
{
if (rnd_mode == MPFR_RNDN &&
(__gmpfr_emin > MPFR_EMAX_MAX + (n + 1) ||
exp < __gmpfr_emin - (n + 1) ||
(inexact >= 0 && mpfr_powerof2_raw (y))))
rnd_mode = MPFR_RNDZ;
return mpfr_underflow (y, rnd_mode, MPFR_SIGN(y));
}
MPFR_SET_EXP (y, exp + n);
}
MPFR_RET (inexact);
}
示例9: mpfr_div_2si
int
mpfr_div_2si (mpfr_ptr y, mpfr_srcptr x, long int n, mp_rnd_t rnd_mode)
{
int inexact;
MPFR_LOG_FUNC (("x[%#R]=%R n=%ld rnd=%d", x, x, n, rnd_mode),
("y[%#R]=%R inexact=%d", y, y, inexact));
inexact = MPFR_UNLIKELY(y != x) ? mpfr_set (y, x, rnd_mode) : 0;
if (MPFR_LIKELY( MPFR_IS_PURE_FP(y) ))
{
mp_exp_t exp = MPFR_GET_EXP (y);
if (MPFR_UNLIKELY( n > 0 && (__gmpfr_emin > MPFR_EMAX_MAX - n ||
exp < __gmpfr_emin + n)) )
{
if (rnd_mode == GMP_RNDN &&
(__gmpfr_emin > MPFR_EMAX_MAX - (n - 1) ||
exp < __gmpfr_emin + (n - 1) ||
(inexact >= 0 && mpfr_powerof2_raw (y))))
rnd_mode = GMP_RNDZ;
return mpfr_underflow (y, rnd_mode, MPFR_SIGN(y));
}
if (MPFR_UNLIKELY(n < 0 && (__gmpfr_emax < MPFR_EMIN_MIN - n ||
exp > __gmpfr_emax + n)) )
return mpfr_overflow (y, rnd_mode, MPFR_SIGN(y));
MPFR_SET_EXP (y, exp - n);
}
return inexact;
}
示例10: mpfr_ui_div
int
mpfr_ui_div (mpfr_ptr y, unsigned long int u, mpfr_srcptr x, mp_rnd_t rnd_mode)
{
mpfr_t uu;
mp_limb_t up[1];
unsigned long cnt;
if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(x)))
{
if (MPFR_IS_NAN(x))
{
MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
else if (MPFR_IS_INF(x)) /* u/Inf = 0 */
{
MPFR_SET_ZERO(y);
MPFR_SET_SAME_SIGN(y,x);
MPFR_RET(0);
}
else /* u / 0 */
{
MPFR_ASSERTD(MPFR_IS_ZERO(x));
if (u)
{
/* u > 0, so y = sign(x) * Inf */
MPFR_SET_SAME_SIGN(y, x);
MPFR_SET_INF(y);
MPFR_RET(0);
}
else
{
/* 0 / 0 */
MPFR_SET_NAN(y);
MPFR_RET_NAN;
}
}
}
else if (MPFR_LIKELY(u != 0))
{
MPFR_TMP_INIT1(up, uu, BITS_PER_MP_LIMB);
MPFR_ASSERTN(u == (mp_limb_t) u);
count_leading_zeros(cnt, (mp_limb_t) u);
up[0] = (mp_limb_t) u << cnt;
MPFR_SET_EXP (uu, BITS_PER_MP_LIMB - cnt);
return mpfr_div (y, uu, x, rnd_mode);
}
else /* u = 0, and x != 0 */
{
MPFR_SET_ZERO(y); /* if u=0, then set y to 0 */
MPFR_SET_SAME_SIGN(y, x); /* u considered as +0: sign(+0/x) = sign(x) */
MPFR_RET(0);
}
}
示例11: mpfr_setmin
void
mpfr_setmin (mpfr_ptr x, mp_exp_t e)
{
mp_size_t xn;
mp_limb_t *xp;
MPFR_SET_EXP (x, e);
xn = (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
xp = MPFR_MANT(x);
xp[xn] = MPFR_LIMB_HIGHBIT;
MPN_ZERO(xp, xn);
}
示例12: set_special
static void
set_special (mpfr_ptr x, unsigned int select)
{
MPFR_ASSERTN (select < SPECIAL_MAX);
switch (select)
{
case 0:
MPFR_SET_NAN (x);
break;
case 1:
MPFR_SET_INF (x);
MPFR_SET_POS (x);
break;
case 2:
MPFR_SET_INF (x);
MPFR_SET_NEG (x);
break;
case 3:
MPFR_SET_ZERO (x);
MPFR_SET_POS (x);
break;
case 4:
MPFR_SET_ZERO (x);
MPFR_SET_NEG (x);
break;
case 5:
mpfr_set_str_binary (x, "1");
break;
case 6:
mpfr_set_str_binary (x, "-1");
break;
case 7:
mpfr_set_str_binary (x, "1e-1");
break;
case 8:
mpfr_set_str_binary (x, "1e+1");
break;
case 9:
mpfr_const_pi (x, MPFR_RNDN);
break;
case 10:
mpfr_const_pi (x, MPFR_RNDN);
MPFR_SET_EXP (x, MPFR_GET_EXP (x)-1);
break;
default:
mpfr_urandomb (x, RANDS);
if (randlimb () & 1)
mpfr_neg (x, x, MPFR_RNDN);
break;
}
}
示例13: mpfr_get_d_2exp
double
mpfr_get_d_2exp (long *expptr, mpfr_srcptr src, mpfr_rnd_t rnd_mode)
{
double ret;
mpfr_exp_t exp;
mpfr_t tmp;
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (src)))
{
int negative;
*expptr = 0;
if (MPFR_IS_NAN (src))
return MPFR_DBL_NAN;
negative = MPFR_IS_NEG (src);
if (MPFR_IS_INF (src))
return negative ? MPFR_DBL_INFM : MPFR_DBL_INFP;
MPFR_ASSERTD (MPFR_IS_ZERO(src));
return negative ? DBL_NEG_ZERO : 0.0;
}
tmp[0] = *src; /* Hack copy mpfr_t */
MPFR_SET_EXP (tmp, 0);
ret = mpfr_get_d (tmp, rnd_mode);
if (MPFR_IS_PURE_FP(src))
{
exp = MPFR_GET_EXP (src);
/* rounding can give 1.0, adjust back to 0.5 <= abs(ret) < 1.0 */
if (ret == 1.0)
{
ret = 0.5;
exp++;
}
else if (ret == -1.0)
{
ret = -0.5;
exp++;
}
MPFR_ASSERTN ((ret >= 0.5 && ret < 1.0)
|| (ret <= -0.5 && ret > -1.0));
MPFR_ASSERTN (exp >= LONG_MIN && exp <= LONG_MAX);
}
else
exp = 0;
*expptr = exp;
return ret;
}
示例14: mpfr_setmax
void
mpfr_setmax (mpfr_ptr x, mpfr_exp_t e)
{
mp_size_t xn, i;
int sh;
mp_limb_t *xp;
MPFR_SET_EXP (x, e);
xn = MPFR_LIMB_SIZE (x);
sh = (mpfr_prec_t) xn * GMP_NUMB_BITS - MPFR_PREC(x);
xp = MPFR_MANT(x);
xp[0] = MP_LIMB_T_MAX << sh;
for (i = 1; i < xn; i++)
xp[i] = MP_LIMB_T_MAX;
}
示例15: mpfr_setmax
void
mpfr_setmax (mpfr_ptr x, mp_exp_t e)
{
mp_size_t xn, i;
int sh;
mp_limb_t *xp;
MPFR_SET_EXP (x, e);
xn = 1 + (MPFR_PREC(x) - 1) / BITS_PER_MP_LIMB;
sh = (mp_prec_t) xn * BITS_PER_MP_LIMB - MPFR_PREC(x);
xp = MPFR_MANT(x);
xp[0] = MP_LIMB_T_MAX << sh;
for (i = 1; i < xn; i++)
xp[i] = MP_LIMB_T_MAX;
}