1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/* tis_inside.c -- Test mpfi_is_inside.
Copyright 2010,
Spaces project, Inria Lorraine
and Salsa project, INRIA Rocquencourt,
and Arenaire project, Inria Rhone-Alpes, France
and Lab. ANO, USTL (Univ. of Lille), France
This file is part of the MPFI Library.
The MPFI Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The MPFI Library 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPFI Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "mpfi-tests.h"
#define ORDER(min, max) \
do { \
if (mpfr_cmp ((min), (max)) > 0) \
mpfr_swap ((min), (max)); \
} while (0)
void
print_error (mpfi_srcptr a, mpfi_srcptr b)
{
printf ("Error: mpfi_is_inside (A, B) returns %d\nA = ",
mpfi_is_inside (a, b));
mpfi_out_str (stdout, 10, 0, a);
printf ("\nB = ");
mpfi_out_str (stdout, 10, 0, b);
printf ("\n");
exit (1);
}
void
check ()
{
mpfi_t i1, i2;
mpfr_t a, b, c, d;
int i;
mpfr_init2 (a, 53);
mpfr_init2 (b, 53);
mpfr_init2 (c, 53);
mpfr_init2 (d, 53);
mpfi_init2 (i1, 53);
mpfi_init2 (i2, 53);
for (i = 0; i <= 1000; ++i) {
/* random numbers a < b < c */
random_mpfr (a);
random_mpfr (b);
random_mpfr (c);
random_mpfr (d);
ORDER (a, b);
ORDER (a, c);
ORDER (a, d);
ORDER (b, c);
ORDER (b, d);
ORDER (c, d);
mpfi_interv_fr (i1, a, b);
mpfi_interv_fr (i2, c, d);
if (mpfi_is_inside (i1, i2) && !mpfr_equal_p (b, c)) {
print_error (i1, i2);
}
if (mpfi_is_inside (i2, i1) && !mpfr_equal_p (b, c)) {
print_error (i2, i1);
}
mpfr_set_nan (&(i1->right));
if (mpfi_is_inside (i1, i2)) {
print_error (i1, i2);
}
mpfi_interv_fr (i1, a, c);
mpfi_interv_fr (i2, b, d);
if (mpfi_is_inside (i1, i2) && !mpfr_equal_p (a, b)
&& !mpfr_equal_p (b, c) && !mpfr_equal_p (c, d)) {
print_error (i1, i2);
}
if (mpfi_is_inside (i2, i1) && !mpfr_equal_p (a, b)
&& !mpfr_equal_p (b, c) && !mpfr_equal_p (c, d)) {
print_error (i2, i1);
}
mpfr_set_nan (&(i1->right));
if (mpfi_is_inside (i1, i2)) {
print_error (i1, i2);
}
mpfi_interv_fr (i1, a, d);
mpfi_interv_fr (i2, b, c);
if (!(mpfr_equal_p (a, b) && mpfr_equal_p (c, d))
&& mpfi_is_inside (i1, i2)) {
print_error (i1, i2);
}
if (!mpfi_is_inside (i2, i1)) {
print_error (i2, i1);
}
mpfr_set_nan (&(i1->right));
if (mpfi_is_inside (i2, i1)) {
print_error (i2, i1);
}
}
mpfr_clear (a);
mpfr_clear (b);
mpfr_clear (c);
mpfr_clear (d);
mpfi_clear (i1);
mpfi_clear (i2);
}
int
main (int argc, char **argv)
{
test_start ();
check ();
test_end ();
return 0;
}
|