本文整理汇总了C++中mpfr_set_nan函数的典型用法代码示例。如果您正苦于以下问题:C++ mpfr_set_nan函数的具体用法?C++ mpfr_set_nan怎么用?C++ mpfr_set_nan使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mpfr_set_nan函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_special
static void
check_special (FILE *fout)
{
mpfr_t x;
mpfr_init (x);
mpfr_set_inf (x, 1);
check (fout, "%Ra", x);
check (fout, "%Rb", x);
check (fout, "%Re", x);
check (fout, "%Rf", x);
check (fout, "%Rg", x);
check_vfprintf (fout, "%Ra", x);
check_vfprintf (fout, "%Rb", x);
check_vfprintf (fout, "%Re", x);
check_vfprintf (fout, "%Rf", x);
check_vfprintf (fout, "%Rg", x);
mpfr_set_inf (x, -1);
check (fout, "%Ra", x);
check (fout, "%Rb", x);
check (fout, "%Re", x);
check (fout, "%Rf", x);
check (fout, "%Rg", x);
check_vfprintf (fout, "%Ra", x);
check_vfprintf (fout, "%Rb", x);
check_vfprintf (fout, "%Re", x);
check_vfprintf (fout, "%Rf", x);
check_vfprintf (fout, "%Rg", x);
mpfr_set_nan (x);
check (fout, "%Ra", x);
check (fout, "%Rb", x);
check (fout, "%Re", x);
check (fout, "%Rf", x);
check (fout, "%Rg", x);
check_vfprintf (fout, "%Ra", x);
check_vfprintf (fout, "%Rb", x);
check_vfprintf (fout, "%Re", x);
check_vfprintf (fout, "%Rf", x);
check_vfprintf (fout, "%Rg", x);
mpfr_clear (x);
}
示例2: check_special
static void
check_special (void)
{
mpfr_t x;
mpfr_init (x);
mpfr_set_inf (x, 1);
check ("%Ra", x);
check ("%Rb", x);
check ("%Re", x);
check ("%Rf", x);
check ("%Rg", x);
check_vprintf ("%Ra", x);
check_vprintf ("%Rb", x);
check_vprintf ("%Re", x);
check_vprintf ("%Rf", x);
check_vprintf ("%Rg", x);
mpfr_set_inf (x, -1);
check ("%Ra", x);
check ("%Rb", x);
check ("%Re", x);
check ("%Rf", x);
check ("%Rg", x);
check_vprintf ("%Ra", x);
check_vprintf ("%Rb", x);
check_vprintf ("%Re", x);
check_vprintf ("%Rf", x);
check_vprintf ("%Rg", x);
mpfr_set_nan (x);
check ("%Ra", x);
check ("%Rb", x);
check ("%Re", x);
check ("%Rf", x);
check ("%Rg", x);
check_vprintf ("%Ra", x);
check_vprintf ("%Rb", x);
check_vprintf ("%Re", x);
check_vprintf ("%Rf", x);
check_vprintf ("%Rg", x);
mpfr_clear (x);
}
示例3: check_nans
static void
check_nans (void)
{
mpfr_t x, y;
int inexact;
mpfr_init2 (x, 123);
mpfr_init2 (y, 123);
/* nan * 1.0 is nan */
mpfr_set_nan (x);
mpfr_clear_flags();
inexact = mpfr_mul_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN ((__gmpfr_flags ^ MPFR_FLAGS_NAN) == 0);
MPFR_ASSERTN (mpfr_nan_p (y));
/* +inf * 1.0 == +inf */
mpfr_set_inf (x, 1);
mpfr_clear_flags();
inexact = mpfr_mul_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN (__gmpfr_flags == 0);
MPFR_ASSERTN (mpfr_inf_p (y));
MPFR_ASSERTN (MPFR_IS_POS (y));
/* +inf * 0.0 is nan */
mpfr_clear_flags();
inexact = mpfr_mul_d (y, x, 0.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN ((__gmpfr_flags ^ MPFR_FLAGS_NAN) == 0);
MPFR_ASSERTN (mpfr_nan_p (y));
/* -inf * 1.0 == -inf */
mpfr_set_inf (x, -1);
mpfr_clear_flags();
inexact = mpfr_mul_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN (__gmpfr_flags == 0);
MPFR_ASSERTN (mpfr_inf_p (y));
MPFR_ASSERTN (MPFR_IS_NEG (y));
mpfr_clear (x);
mpfr_clear (y);
}
示例4: main
int
main (int argc, char *argv[])
{
double x, z; mpfr_t w; unsigned long k;
mpfr_init2(w, 53);
mpfr_set_inf (w, 1);
mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
if (!MPFR_IS_INF(w)) { fprintf(stderr, "Inf != Inf"); exit(-1); }
mpfr_set_nan (w);
mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
if (!MPFR_IS_NAN(w)) { fprintf(stderr, "NaN != NaN"); exit(-1); }
SEED_RAND (time(NULL));
for (k = 0; k < 100000; k++) {
x = DBL_RAND ();
mpfr_set_d (w, x, 0);
mpfr_mul_2exp (w, w, 10, GMP_RNDZ);
if (x != (z = mpfr_get_d1 (w)/1024))
{
fprintf(stderr, "%f != %f\n", x, z);
return -1;
}
mpfr_set_d(w, x, 0);
mpfr_div_2exp(w, w, 10, GMP_RNDZ);
if (x != (z = mpfr_get_d1 (w)*1024))
{
fprintf(stderr, "%f != %f\n", x, z);
mpfr_clear(w);
return -1;
}
}
mpfr_clear(w);
return 0;
}
示例5: check_nans
static void
check_nans (void)
{
#if !defined(MPFR_ERRDIVZERO)
mpfr_t x, y;
int inexact;
mpfr_init2 (x, 123);
mpfr_init2 (y, 123);
/* nan + 1.0 is nan */
mpfr_set_nan (x);
mpfr_clear_flags ();
inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN ((__gmpfr_flags ^ MPFR_FLAGS_NAN) == 0);
MPFR_ASSERTN (mpfr_nan_p (y));
/* +inf + 1.0 == +inf */
mpfr_set_inf (x, 1);
mpfr_clear_flags ();
inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN (__gmpfr_flags == 0);
MPFR_ASSERTN (mpfr_inf_p (y));
MPFR_ASSERTN (MPFR_IS_POS (y));
/* -inf + 1.0 == -inf */
mpfr_set_inf (x, -1);
mpfr_clear_flags ();
inexact = mpfr_add_d (y, x, 1.0, MPFR_RNDN);
MPFR_ASSERTN (inexact == 0);
MPFR_ASSERTN (__gmpfr_flags == 0);
MPFR_ASSERTN (mpfr_inf_p (y));
MPFR_ASSERTN (MPFR_IS_NEG (y));
mpfr_clear (x);
mpfr_clear (y);
#endif
}
示例6: special
static void
special (void)
{
int inex;
mpfr_t x;
mpz_t z;
int i;
mpfr_exp_t e;
mpfr_init2 (x, 2);
mpz_init (z);
for (i = -1; i <= 1; i++)
{
if (i != 0)
mpfr_set_nan (x);
else
mpfr_set_inf (x, i);
mpfr_clear_flags ();
inex = mpfr_get_z (z, x, MPFR_RNDN);
if (!mpfr_erangeflag_p () || inex != 0 || mpz_cmp_ui (z, 0) != 0)
{
printf ("special() failed on mpfr_get_z for i = %d\n", i);
exit (1);
}
mpfr_clear_flags ();
e = mpfr_get_z_2exp (z, x);
if (!mpfr_erangeflag_p () || e != __gmpfr_emin ||
mpz_cmp_ui (z, 0) != 0)
{
printf ("special() failed on mpfr_get_z_2exp for i = %d\n", i);
exit (1);
}
}
mpfr_clear (x);
mpz_clear (z);
}
示例7: special
static void
special (void)
{
mpfr_t x;
int inex;
mpfr_init (x);
mpfr_set_nan (x);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
mpfr_set_inf (x, -1);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
mpfr_set_inf (x, 1);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) > 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_neg (x, x, MPFR_RNDN);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
mpfr_set_si (x, -1, MPFR_RNDN);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
mpfr_set_si (x, 1, MPFR_RNDN);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x) && inex == 0);
mpfr_clear (x);
}
示例8: special
static void
special (void)
{
mpfr_t x;
mpfr_init (x);
mpfr_set_nan (x);
mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
mpfr_set_inf (x, 1);
mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
mpfr_set_inf (x, -1);
mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
mpfr_neg (x, x, MPFR_RNDN);
mpfr_out_str (fout, 10, 0, x, MPFR_RNDN);
mpfr_clear (x);
}
示例9: check_special
static void
check_special (void)
{
mpfr_t x, y;
mpfr_exp_t emin;
mpfr_init (x);
mpfr_init (y);
mpfr_set_nan (x);
mpfr_sqr (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (y));
mpfr_set_inf (x, 1);
mpfr_sqr (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0);
mpfr_set_inf (x, -1);
mpfr_sqr (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_sqr (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_zero_p (y));
emin = mpfr_get_emin ();
mpfr_set_emin (0);
mpfr_set_ui (x, 1, MPFR_RNDN);
mpfr_div_2ui (x, x, 1, MPFR_RNDN);
MPFR_ASSERTN (!mpfr_zero_p (x));
mpfr_sqr (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_zero_p (y));
mpfr_set_emin (emin);
mpfr_clear (y);
mpfr_clear (x);
}
示例10: fmpr_get_mpfr
int
fmpr_get_mpfr(mpfr_t x, const fmpr_t y, mpfr_rnd_t rnd)
{
int r;
if (fmpr_is_special(y))
{
if (fmpr_is_zero(y)) mpfr_set_zero(x, 0);
else if (fmpr_is_pos_inf(y)) mpfr_set_inf(x, 1);
else if (fmpr_is_neg_inf(y)) mpfr_set_inf(x, -1);
else mpfr_set_nan(x);
r = 0;
}
else if (COEFF_IS_MPZ(*fmpr_expref(y)))
{
flint_printf("exception: exponent too large to convert to mpfr");
flint_abort();
r = 0; /* dummy return because flint_abort() is not declared noreturn */
}
else
{
if (!COEFF_IS_MPZ(*fmpr_manref(y)))
#if defined(__MINGW64__) || defined(_MSC_VER)
r = mpfr_set_sj_2exp(x, *fmpr_manref(y), *fmpr_expref(y), rnd);
#else
r = mpfr_set_si_2exp(x, *fmpr_manref(y), *fmpr_expref(y), rnd);
#endif
else
r = mpfr_set_z_2exp(x, COEFF_TO_PTR(*fmpr_manref(y)), *fmpr_expref(y), rnd);
if (!mpfr_regular_p(x))
{
flint_printf("exception: exponent too large to convert to mpfr");
flint_abort();
}
}
示例11: special
static void
special (void)
{
mpfr_t x, y;
int inex;
mpfr_init (x);
mpfr_init (y);
mpfr_set_nan (x);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for gamma(NaN)\n");
exit (1);
}
mpfr_set_inf (x, -1);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for gamma(-Inf)\n");
exit (1);
}
mpfr_set_inf (x, 1);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for gamma(+Inf)\n");
exit (1);
}
mpfr_set_ui (x, 0, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for gamma(+0)\n");
exit (1);
}
mpfr_set_ui (x, 0, GMP_RNDN);
mpfr_neg (x, x, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) > 0)
{
printf ("Error for gamma(-0)\n");
exit (1);
}
mpfr_set_ui (x, 1, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error for gamma(1)\n");
exit (1);
}
mpfr_set_si (x, -1, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for gamma(-1)\n");
exit (1);
}
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 53);
#define CHECK_X1 "1.0762904832837976166"
#define CHECK_Y1 "0.96134843256452096050"
mpfr_set_str (x, CHECK_X1, 10, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
mpfr_set_str (x, CHECK_Y1, 10, GMP_RNDN);
if (mpfr_cmp (y, x))
{
printf ("mpfr_lngamma("CHECK_X1") is wrong:\n"
"expected ");
mpfr_print_binary (x); putchar ('\n');
printf ("got ");
mpfr_print_binary (y); putchar ('\n');
exit (1);
}
#define CHECK_X2 "9.23709516716202383435e-01"
#define CHECK_Y2 "1.0502315560291053398"
mpfr_set_str (x, CHECK_X2, 10, GMP_RNDN);
mpfr_gamma (y, x, GMP_RNDN);
mpfr_set_str (x, CHECK_Y2, 10, GMP_RNDN);
if (mpfr_cmp (y, x))
{
printf ("mpfr_lngamma("CHECK_X2") is wrong:\n"
"expected ");
mpfr_print_binary (x); putchar ('\n');
printf ("got ");
mpfr_print_binary (y); putchar ('\n');
exit (1);
}
//.........这里部分代码省略.........
示例12: check_get_d_2exp_inf_nan
static void
check_get_d_2exp_inf_nan (void)
{
#if !defined(MPFR_ERRDIVZERO)
double var_d;
long exp;
mpfr_t var;
mpfr_init2 (var, MPFR_PREC_MIN);
mpfr_set_nan (var);
var_d = mpfr_get_d_2exp (&exp, var, MPFR_RNDN);
if (!DOUBLE_ISNAN (var_d))
{
printf ("mpfr_get_d_2exp with a NAN mpfr value returned a wrong value :\n"
" waiting for %g got %g\n", MPFR_DBL_NAN, var_d);
exit (1);
}
mpfr_set_zero (var, 1);
var_d = mpfr_get_d_2exp (&exp, var, MPFR_RNDN);
if ((exp != 0) || (var_d != 0.0))
{
printf ("mpfr_get_d_2exp with a +0.0 mpfr value returned a wrong value :\n"
" double waiting for 0.0 got %g\n exp waiting for 0 got %ld\n",
var_d, exp);
exit (1);
}
mpfr_set_zero (var, -1);
var_d = mpfr_get_d_2exp (&exp, var, MPFR_RNDN);
if ((exp != 0) || (var_d != DBL_NEG_ZERO))
{
printf ("mpfr_get_d_2exp with a +0.0 mpfr value returned a wrong value :\n"
" double waiting for %g got %g\n exp waiting for 0 got %ld\n",
DBL_NEG_ZERO, var_d, exp);
exit (1);
}
mpfr_set_inf (var, 1);
var_d = mpfr_get_d_2exp (&exp, var, MPFR_RNDN);
if (var_d != MPFR_DBL_INFP)
{
printf ("mpfr_get_d_2exp with a +Inf mpfr value returned a wrong value :\n"
" waiting for %g got %g\n", MPFR_DBL_INFP, var_d);
exit (1);
}
mpfr_set_inf (var, -1);
var_d = mpfr_get_d_2exp (&exp, var, MPFR_RNDN);
if (var_d != MPFR_DBL_INFM)
{
printf ("mpfr_get_d_2exp with a -Inf mpfr value returned a wrong value :\n"
" waiting for %g got %g\n", MPFR_DBL_INFM, var_d);
exit (1);
}
mpfr_clear (var);
#endif
}
示例13: main
int
main (int argc, char *argv[])
{
mpfr_t x, y;
int inex;
tests_start_mpfr ();
mpfr_init (x);
mpfr_init (y);
/* special values */
mpfr_set_nan (x);
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN(mpfr_nan_p (y));
mpfr_set_inf (x, 1); /* +Inf */
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
mpfr_set_inf (x, -1); /* -Inf */
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y));
mpfr_set_ui (x, 0, MPFR_RNDN); /* +0 */
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0); /* j0(+0)=1 */
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_neg (x, x, MPFR_RNDN); /* -0 */
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0); /* j0(-0)=1 */
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 53);
mpfr_set_ui (x, 1, MPFR_RNDN);
mpfr_j0 (y, x, MPFR_RNDN);
mpfr_set_str_binary (x, "0.1100001111100011111111101101111010111101110001111");
if (mpfr_cmp (x, y))
{
printf ("Error in mpfr_j0 for x=1, rnd=MPFR_RNDN\n");
printf ("Expected "); mpfr_dump (x);
printf ("Got "); mpfr_dump (y);
exit (1);
}
mpfr_set_si (x, -1, MPFR_RNDN);
mpfr_j0 (y, x, MPFR_RNDN);
mpfr_set_str_binary (x, "0.1100001111100011111111101101111010111101110001111");
if (mpfr_cmp (x, y))
{
printf ("Error in mpfr_j0 for x=-1, rnd=MPFR_RNDN\n");
printf ("Expected "); mpfr_dump (x);
printf ("Got "); mpfr_dump (y);
exit (1);
}
/* Bug reported on 2007-07-03 by Sisyphus (assertion failed in r4619) */
mpfr_set_si (x, 70000, MPFR_RNDN);
mpfr_j0 (y, x, MPFR_RNDN);
/* Bug reported by Kevin Rauch on 27 Oct 2007 */
mpfr_set_prec (x, 7);
mpfr_set_prec (y, 7);
mpfr_set_si (x, -100, MPFR_RNDN);
mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN (! mpfr_nan_p (y) && mpfr_cmp_ui_2exp (y, 41, -11) == 0);
/* Case for which s = 0 in mpfr_jn */
mpfr_set_prec (x, 44);
mpfr_set_prec (y, 44);
mpfr_set_si (x, 2, MPFR_RNDN);
mpfr_clear_flags ();
inex = mpfr_j0 (y, x, MPFR_RNDN);
MPFR_ASSERTN (__gmpfr_flags == MPFR_FLAGS_INEXACT);
mpfr_set_str (x, "0x.e5439fd9267p-2", 0, MPFR_RNDN);
if (! mpfr_equal_p (y, x))
{
printf ("Error on 2:\n");
printf ("Expected ");
mpfr_dump (x);
printf ("Got ");
mpfr_dump (y);
exit (1);
}
if (inex >= 0)
{
printf ("Bad ternary value on 2: expected negative, got %d\n", inex);
exit (1);
}
mpfr_clear (x);
mpfr_clear (y);
test_generic (2, 100, 10);
data_check ("data/j0", mpfr_j0, "mpfr_j0");
tests_end_mpfr ();
//.........这里部分代码省略.........
示例14: special
static void
special (void)
{
mpfr_t x, y;
int inex;
int sign;
mpfr_init (x);
mpfr_init (y);
mpfr_set_nan (x);
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_nan_p (y))
{
printf ("Error for lgamma(NaN)\n");
exit (1);
}
mpfr_set_inf (x, -1);
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for lgamma(-Inf)\n");
exit (1);
}
mpfr_set_inf (x, 1);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0 || sign != 1)
{
printf ("Error for lgamma(+Inf)\n");
exit (1);
}
mpfr_set_ui (x, 0, GMP_RNDN);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0 || sign != 1)
{
printf ("Error for lgamma(+0)\n");
exit (1);
}
mpfr_set_ui (x, 0, GMP_RNDN);
mpfr_neg (x, x, GMP_RNDN);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0 || sign != -1)
{
printf ("Error for lgamma(-0)\n");
exit (1);
}
mpfr_set_ui (x, 1, GMP_RNDN);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (MPFR_IS_NAN (y) || mpfr_cmp_ui (y, 0) || MPFR_IS_NEG (y) || sign != 1)
{
printf ("Error for lgamma(1)\n");
exit (1);
}
mpfr_set_si (x, -1, GMP_RNDN);
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (!mpfr_inf_p (y) || mpfr_sgn (y) < 0)
{
printf ("Error for lgamma(-1)\n");
exit (1);
}
mpfr_set_ui (x, 2, GMP_RNDN);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
if (MPFR_IS_NAN (y) || mpfr_cmp_ui (y, 0) || MPFR_IS_NEG (y) || sign != 1)
{
printf ("Error for lgamma(2)\n");
exit (1);
}
mpfr_set_prec (x, 53);
mpfr_set_prec (y, 53);
#define CHECK_X1 "1.0762904832837976166"
#define CHECK_Y1 "-0.039418362817587634939"
mpfr_set_str (x, CHECK_X1, 10, GMP_RNDN);
sign = -17;
mpfr_lgamma (y, &sign, x, GMP_RNDN);
mpfr_set_str (x, CHECK_Y1, 10, GMP_RNDN);
if (mpfr_equal_p (y, x) == 0 || sign != 1)
{
printf ("mpfr_lgamma("CHECK_X1") is wrong:\n"
"expected ");
mpfr_print_binary (x); putchar ('\n');
printf ("got ");
mpfr_print_binary (y); putchar ('\n');
exit (1);
}
//.........这里部分代码省略.........
示例15: check_nans
static void
check_nans (void)
{
mpfr_t x, y;
mpfr_init2 (x, 123L);
mpfr_init2 (y, 123L);
mpfr_set_nan (x);
test_cos (y, x, MPFR_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(NaN) != NaN\n");
exit (1);
}
mpfr_set_inf (x, 1);
test_cos (y, x, MPFR_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(Inf) != NaN\n");
exit (1);
}
mpfr_set_inf (x, -1);
test_cos (y, x, MPFR_RNDN);
if (! mpfr_nan_p (y))
{
printf ("Error: cos(-Inf) != NaN\n");
exit (1);
}
/* cos(+/-0) = 1 */
mpfr_set_ui (x, 0, MPFR_RNDN);
test_cos (y, x, MPFR_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error: cos(+0) != 1\n");
exit (1);
}
mpfr_neg (x, x, MPFR_RNDN);
test_cos (y, x, MPFR_RNDN);
if (mpfr_cmp_ui (y, 1))
{
printf ("Error: cos(-0) != 1\n");
exit (1);
}
/* Compute ~Pi/2 to check */
/* FIXME: Too slow!
mpfr_set_prec (x, 20000);
mpfr_const_pi (x, MPFR_RNDD); mpfr_div_2ui (x, x, 1, MPFR_RNDN);
mpfr_set_prec (y, 24);
test_cos (y, x, MPFR_RNDN);
if (mpfr_cmp_str (y, "0.111001010110100011000001E-20000", 2, MPFR_RNDN))
{
printf("Error computing cos(~Pi/2)\n");
mpfr_dump (y);
exit (1);
} */
mpfr_clear (x);
mpfr_clear (y);
}