void mp_Imul (mp_interval_t *rop, mp_interval_t op1, mp_interval_t op2) { // DECLARE AUX MPFR_T VARIABLE TO STORE CROSSED PRODUCTS mpfr_t aux; mpfr_init (aux); mpfr_t ropA; mpfr_init (ropA); mpfr_t ropB; mpfr_init (ropB); // FIRST CANDIDATE TO LEFT BOUNDARY mpfr_mul (ropA, op1.a, op2.a, MPFR_RNDD); mpfr_mul (aux, op1.a, op2.b, MPFR_RNDD); mpfr_min (ropA, ropA, aux, MPFR_RNDD); mpfr_mul (aux, op1.b, op2.a, MPFR_RNDD); mpfr_min (ropA, ropA, aux, MPFR_RNDD); mpfr_mul (aux, op1.b, op2.b, MPFR_RNDD); mpfr_min (ropA, ropA, aux, MPFR_RNDD); // FIRST CANDIDATE TO RIGHT BOUNDARY mpfr_mul (ropB, op1.a, op2.a, MPFR_RNDU); mpfr_mul (aux, op1.a, op2.b, MPFR_RNDU); mpfr_max (ropB, ropB, aux, MPFR_RNDU); mpfr_mul (aux, op1.b, op2.a, MPFR_RNDU); mpfr_max (ropB, ropB, aux, MPFR_RNDU); mpfr_mul (aux, op1.b, op2.b, MPFR_RNDU); mpfr_max (rop->b, ropB, aux, MPFR_RNDU); mpfr_set (rop->a, ropA, MPFR_RNDD); // CLEAN AUX VARIABLE mpfr_clear (aux); mpfr_clear (ropA); mpfr_clear (ropB); }
SeedValue seed_mpfr_min (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue args[], SeedException *exception) { mpfr_rnd_t rnd; mpfr_ptr rop, op1, op2; gint ret; CHECK_ARG_COUNT("mpfr.min", 3); rop = seed_object_get_private(this_object); rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception); if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) { op1 = seed_object_get_private(args[0]); op2 = seed_object_get_private(args[1]); } else { TYPE_EXCEPTION("mpfr.min", "mpfr_t"); } ret = mpfr_min(rop, op1, op2, rnd); return seed_value_from_int(ctx, ret, exception); }
int mp_IntersectInterval (mp_interval_t *rop, mp_interval_t op1, mp_interval_t op2) { //rop->a = MAX (op1.a, op2.a); mpfr_max (rop->a, op1.a, op2.a, MPFR_RNDD); //rop->b = MIN (op1.b, op2.b); mpfr_min (rop->b, op1.b, op2.b, MPFR_RNDU); //if (rop->a < rop->b) return 1; if (mpfr_cmp (rop->a, rop->b) < 0) return 1; return 0; }
int main (void) { mpfr_t x, y, z; tests_start_mpfr (); mpfr_init (x); mpfr_init (y); mpfr_init (z); /* case x=NaN && y=NAN */ mpfr_set_nan (x); mpfr_set_nan (y); mpfr_min (z, x, y, MPFR_RNDN); if (!mpfr_nan_p (z)) { printf ("Error in mpfr_min (NaN, NaN)\n"); exit (1); } mpfr_max (z, x, y, MPFR_RNDN); if (!mpfr_nan_p (z)) { printf ("Error in mpfr_max (NaN, NaN)\n"); exit (1); } /* case x=NaN */ mpfr_set_nan (x); mpfr_set_ui (y, 0, MPFR_RNDN); mpfr_min (z, x, y, MPFR_RNDN); if (mpfr_cmp_ui (z, 0)) { printf ("Error in mpfr_min (NaN, 0)\n"); exit (1); } mpfr_min (z, y, x, MPFR_RNDN); if (mpfr_cmp_ui (z, 0)) { printf ("Error in mpfr_min (0, NaN)\n"); exit (1); } mpfr_max (z, x, y, MPFR_RNDN); if (mpfr_cmp_ui (z, 0)) { printf ("Error in mpfr_max (NaN, 0)\n"); exit (1); } mpfr_max (z, y, x, MPFR_RNDN); if (mpfr_cmp_ui (z, 0)) { printf ("Error in mpfr_max (0, NaN)\n"); exit (1); } /* Case x=0+ and x=0- */ mpfr_set_ui (x, 0, MPFR_RNDN); mpfr_set_ui (y, 0, MPFR_RNDN); MPFR_SET_NEG(y); mpfr_max (z, x, y, MPFR_RNDN); if (!MPFR_IS_ZERO(z) || MPFR_IS_NEG(z)) { printf ("Error in mpfr_max (0+, 0-)\n"); exit (1); } mpfr_min (z, x, y, MPFR_RNDN); if (!MPFR_IS_ZERO(z) || MPFR_IS_POS(z)) { printf ("Error in mpfr_min (0+, 0-)\n"); exit (1); } /* Case x=0- and y=0+ */ mpfr_set_ui (x, 0, MPFR_RNDN); MPFR_SET_NEG(x); mpfr_set_ui (y, 0, MPFR_RNDN); mpfr_max (z, x, y, MPFR_RNDN); if (!MPFR_IS_ZERO(z) || MPFR_IS_NEG(z)) { printf ("Error in mpfr_max (0+, 0-)\n"); exit (1); } mpfr_min (z, x, y, MPFR_RNDN); if (!MPFR_IS_ZERO(z) || MPFR_IS_POS(z)) { printf ("Error in mpfr_min (0+, 0-)\n"); exit (1); } /* case x=+Inf */ mpfr_set_inf (x, 1); mpfr_set_si (y, -12, MPFR_RNDN); mpfr_min (z, x, y, MPFR_RNDN); if ( mpfr_cmp_si (z, -12) ) { printf ("Error in mpfr_min (+Inf, -12)\n"); exit (1); } mpfr_max (z, x, y, MPFR_RNDN); if ( !MPFR_IS_INF(z) || MPFR_IS_NEG(z) ) { printf ("Error in mpfr_max (+Inf, 12)\n"); exit (1); } /* case x=-Inf */ mpfr_set_inf (x, -1); mpfr_set_ui (y, 12, MPFR_RNDN); mpfr_max (z, x, y, MPFR_RNDN); if ( mpfr_cmp_ui (z, 12) ) { printf ("Error in mpfr_max (-Inf, 12)\n"); exit (1); } mpfr_min (z, x, y, MPFR_RNDN); if ( !MPFR_IS_INF(z) || MPFR_IS_POS(z) ) { printf ("Error in mpfr_min (-Inf, 12)\n"); exit (1); } /* case x=17 and y=42 */ mpfr_set_ui (x, 17, MPFR_RNDN); mpfr_set_ui (y, 42, MPFR_RNDN); mpfr_max (z, x, y, MPFR_RNDN); if ( mpfr_cmp_ui (z, 42) ) { printf ("Error in mpfr_max (17, 42)\n"); exit (1); } mpfr_max (z, y, x, MPFR_RNDN); if ( mpfr_cmp_ui (z, 42) ) { printf ("Error in mpfr_max (42, 17)\n"); exit (1); } mpfr_min (z, y, x, MPFR_RNDN); if ( mpfr_cmp_ui (z, 17) ) { printf ("Error in mpfr_min (42, 17)\n"); exit (1); } mpfr_clear (x); mpfr_clear (y); mpfr_clear (z); tests_end_mpfr (); return 0; }