static void cmp_tests (void) { mpfr_t x, y; long i; mpfr_inits (x, y, (mpfr_ptr) 0); for (i = 0; i < 80000; i++) { mpfr_prec_t precx, precy; int signx, signy, cmp; unsigned int cmpbool = 0; precx = (randlimb () % 17) * 11 + MPFR_PREC_MIN; precy = (randlimb () % 17) * 11 + MPFR_PREC_MIN; mpfr_set_prec (x, precx); mpfr_set_prec (y, precy); mpfr_urandomb (x, RANDS); mpfr_urandomb (y, RANDS); signx = randlimb () & 1; signy = randlimb () % 256 ? signx : 1 - signx; /* signy = signx most of the time (most interesting case) */ if (signx) mpfr_neg (x, x, MPFR_RNDN); if (signy) mpfr_neg (y, y, MPFR_RNDN); if (i <= 1) mpfr_set_nan (x); if (i == 0 || i == 2) mpfr_set_nan (y); if (mpfr_greater_p (x, y)) cmpbool |= 0x01; if (mpfr_greaterequal_p (x, y)) cmpbool |= 0x02; if (mpfr_less_p (x, y)) cmpbool |= 0x04; if (mpfr_lessequal_p (x, y)) cmpbool |= 0x08; if (mpfr_lessgreater_p (x, y)) cmpbool |= 0x10; if (mpfr_equal_p (x, y)) cmpbool |= 0x20; if (mpfr_unordered_p (x, y)) cmpbool |= 0x40; if ((i <= 2 && cmpbool != 0x40) || (i > 2 && (cmp = mpfr_cmp (x, y), (cmp == 0 && cmpbool != 0x2a) || (cmp < 0 && cmpbool != 0x1c) || (cmp > 0 && cmpbool != 0x13)))) { printf ("Error in cmp_tests for\nx = "); mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN); printf (" and\ny = "); mpfr_out_str (stdout, 2, 0, y, MPFR_RNDN); printf ("\n"); exit (1); } } mpfr_clears (x, y, (mpfr_ptr) 0); }
static void eq_tests (void) { mpfr_t x, y; long i; mpfr_inits (x, y, (mpfr_ptr) 0); for (i = 0; i < 20000; i++) { mpfr_prec_t precx; precx = (randlimb () % 17) * 11 + MPFR_PREC_MIN; mpfr_set_prec (x, precx); mpfr_set_prec (y, precx + (randlimb () % 64)); mpfr_urandomb (x, RANDS); if (randlimb () & 1) mpfr_neg (x, x, MPFR_RNDN); mpfr_set (y, x, MPFR_RNDN); /* exact -> x = y */ if (mpfr_greater_p (x, y) || !mpfr_greaterequal_p (x, y) || mpfr_less_p (x, y) || !mpfr_lessequal_p (x, y) || mpfr_lessgreater_p (x, y) || !mpfr_equal_p (x, y) || mpfr_unordered_p (x, y)) { printf ("Error in eq_tests for x = "); mpfr_out_str (stdout, 2, 0, x, MPFR_RNDN); printf ("\n"); exit (1); } } mpfr_clears (x, y, (mpfr_ptr) 0); }
void ovm_q_gt(oregister_t *l, oregister_t *r) { l->t = t_word; switch (r->t) { case t_void: l->v.w = mpq_sgn(oqr(l)) > 0; break; case t_word: l->v.w = mpq_cmp_si(oqr(l), r->v.w, 1) > 0; break; case t_float: l->v.w = mpq_get_d(oqr(l)) > r->v.d; break; case t_mpz: mpq_set_z(oqr(r), ozr(r)); l->v.w = mpq_cmp(oqr(l), oqr(r)) > 0; break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); l->v.w = mpq_cmp(oqr(l), oqr(r)) > 0; break; case t_mpq: l->v.w = mpq_cmp(oqr(l), oqr(r)) > 0; break; case t_mpr: mpfr_set_z(orr(l), ozr(l), thr_rnd); l->v.w = mpfr_greater_p(orr(l), orr(r)); break; default: ovm_raise(except_not_a_real_number); } }
depth_t frac_generalized_celtic_mpfr( depth_t depth, mpfr_t bail, mpfr_t wim, mpfr_t wre, mpfr_t c_im, mpfr_t c_re, mpfr_t wim2, mpfr_t wre2, mpfr_t t1) { depth_t wz; for (wz = 1; wz <= depth; wz++) { /* wim = 2.0 * wre * wim + c_im; */ mpfr_mul( t1, wre, wim, GMP_RNDN); mpfr_mul_si(t1, t1, 2, GMP_RNDN); mpfr_add( wim, t1, c_im, GMP_RNDN); /* wre = wre2 - wim2 + c_re; */ mpfr_sub( t1, wre2, wim2, GMP_RNDN); mpfr_abs( t1, t1, GMP_RNDN); mpfr_add( wre, t1, c_re, GMP_RNDN); /* wim2 = wim * wim; */ mpfr_mul( wim2, wim, wim, GMP_RNDN); /* wre2 = wre * wre; */ mpfr_mul( wre2, wre, wre, GMP_RNDN); /* if ((wim2 + wre2) > frs_bail) */ mpfr_add( t1, wim2, wre2, GMP_RNDN); if (mpfr_greater_p(t1, bail)) return wz; } return 0; }
SeedValue seed_mpfr_greater_p (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue args[], SeedException *exception) { mpfr_ptr rop, op; gboolean ret; CHECK_ARG_COUNT("mpfr.greater_p", 1); rop = seed_object_get_private(this_object); if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) ) { op = seed_object_get_private(args[0]); } else { TYPE_EXCEPTION("mpfr.greater_p", "mpfr_t"); } ret = mpfr_greater_p(rop, op); return seed_value_from_boolean(ctx, ret, exception); }
/* Bug found by Christoph Lauter. */ static void bug20081028 (void) { mpfr_t x; const char *s = "0.10000000000000000000000000000001E1"; mpfr_init2 (x, 32); mpfr_set_str (x, "1.00000000000000000006", 10, MPFR_RNDU); if (! mpfr_greater_p (x, __gmpfr_one)) { printf ("Error in bug20081028:\nExpected %s\nGot ", s); mpfr_dump (x); exit (1); } mpfr_clear (x); }
bool operator >(const real & a, const real & b) { return mpfr_greater_p(a.r, b.r) != 0; }