[Mpfi-commits] r326 - trunk/mpfi/tests

ptheveny at users.gforge.inria.fr ptheveny at users.gforge.inria.fr
Jeu 24 Juin 14:20:36 CEST 2010


Author: ptheveny
Date: 2010-06-24 14:20:35 +0200 (Thu, 24 Jun 2010)
New Revision: 326

Added:
   trunk/mpfi/tests/tis_inside_d.c
   trunk/mpfi/tests/tis_inside_si.c
   trunk/mpfi/tests/tis_inside_ui.c
   trunk/mpfi/tests/tis_strictly_inside.c
Modified:
   trunk/mpfi/tests/Makefile.am
Log:
Add tests for mpfi_is_inside functions.

Modified: trunk/mpfi/tests/Makefile.am
===================================================================
--- trunk/mpfi/tests/Makefile.am	2010-06-24 12:17:17 UTC (rev 325)
+++ trunk/mpfi/tests/Makefile.am	2010-06-24 12:20:35 UTC (rev 326)
@@ -17,7 +17,8 @@
     tdiv_2si tdiv_2ui tdiv_d tdiv_fr tdiv_q tdiv_ui tdiv_si	\
     tdiv_z terror texp texp2 texpm1 tfr_div tfr_sub thypot	\
     tincrease tinit_set tintersect tinterv_d tinterv_fr		\
-    tinterv_q tinterv_si tinterv_ui tinterv_z tinv tget_d	\
+    tinterv_q tinterv_si tinterv_ui tinterv_z tinv		\
+    tis_inside_d tis_inside_si tis_inside_ui tget_d		\
     tis_empty tio_str tget_endpoints tget_fr thas_zero tlog	\
     tlog10 tlog1p tlog2 tmag tmid tmig tmul tmul_2exp		\
     tmul_2si tmul_2ui tmul_d tmul_fr tmul_q tmul_ui tmul_si	\

Added: trunk/mpfi/tests/tis_inside_d.c
===================================================================
--- trunk/mpfi/tests/tis_inside_d.c	                        (rev 0)
+++ trunk/mpfi/tests/tis_inside_d.c	2010-06-24 12:20:35 UTC (rev 326)
@@ -0,0 +1,102 @@
+/* tis_inside_d.c -- Test mpfi_is_inside_d.
+
+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 <float.h>
+#include "mpfi-tests.h"
+
+/* Warning: DBL_MANT_DIG is not necessary a number of bits */
+#ifndef DBL_MANT_DIG
+#define DBL_MANT_DIG 53
+#endif
+
+#define ORDER(min, max) \
+  do {                  \
+    if (min > max) {    \
+      double tmp;       \
+      tmp = min;        \
+      min = max;        \
+      max = tmp;}       \
+  } while (0)
+
+static void
+print_error (double x, mpfi_srcptr i)
+{
+  printf ("Error: mpfi_is_inside_d (x, I) returns %d\nx = %g\nI = ",
+          mpfi_is_inside_d (x, i), x);
+  mpfi_out_str (stdout, 10, 0, i);
+  printf ("\n");
+
+  exit (1);
+}
+
+static void
+check_regular ()
+{
+  mpfi_t interval;
+  double a, b, c;
+  int i;
+
+  mpfi_init2 (interval, DBL_MANT_DIG);
+
+  for (i = 0; i <= 1000; ++i) {
+    /* random numbers a < b < c */
+    a = random_double ();
+    b = random_double ();
+    c = random_double ();
+    ORDER (a, b);
+    ORDER (a, c);
+    ORDER (b, c);
+
+    mpfi_interv_d (interval, b, c);
+    if (a != b && mpfi_is_inside_d (a, interval)) {
+      print_error (a, interval);
+    }
+
+    mpfi_interv_d (interval, a, c);
+    if (!mpfi_is_inside_d (b, interval)) {
+      print_error (b, interval);
+    }
+
+    mpfi_interv_d (interval, a, b);
+    if (c != b && mpfi_is_inside_d (c, interval)) {
+      print_error (c, interval);
+    }
+  }
+
+  mpfi_clear (interval);
+}
+
+int
+main (int argc, char **argv)
+{
+  test_start ();
+
+  check_regular ();
+
+  test_end ();
+
+  return 0;
+}

Added: trunk/mpfi/tests/tis_inside_si.c
===================================================================
--- trunk/mpfi/tests/tis_inside_si.c	                        (rev 0)
+++ trunk/mpfi/tests/tis_inside_si.c	2010-06-24 12:20:35 UTC (rev 326)
@@ -0,0 +1,115 @@
+/* tis_inside_si.c -- Test mpfi_is_inside_si.
+
+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"
+
+#include <limits.h>
+#ifndef LONG_MAX
+# define LONG_MAX +2147483647
+#endif
+
+#define ORDER(min, max)  \
+  do {                   \
+    if (min > max) {     \
+      long tmp;          \
+      tmp = min;         \
+      min = max;         \
+      max = tmp;}        \
+  } while (0)
+
+static void
+print_error (long x, mpfi_srcptr i)
+{
+  printf ("Error: mpfi_is_inside_si (x, I) returns %d\nx = %ld\nI = ",
+          mpfi_is_inside_si (x, i), x);
+  mpfi_out_str (stdout, 10, 0, i);
+  printf ("\n");
+
+  exit (1);
+}
+
+static void
+check ()
+{
+  mpfi_t interval;
+  long a, b, c;
+  int i;
+
+  i = 1;
+  a = LONG_MAX;
+  while (a >>= 1) i++;
+
+  mpfi_init2 (interval, i);
+
+  for (i = 0; i <= 1000; ++i) {
+    /* random numbers a < b < c */
+    a = random_si ();
+    b = random_si ();
+    c = random_si ();
+    ORDER (a, b);
+    ORDER (a, c);
+    ORDER (b, c);
+
+    mpfi_interv_si (interval, b, c);
+    if (a != b && mpfi_is_inside_si (a, interval)) {
+      print_error (a, interval);
+    }
+
+    mpfr_set_nan (&(interval->left));
+    if (mpfi_is_inside_si (a, interval)) {
+      print_error (a, interval);
+    }
+
+    mpfi_interv_si (interval, a, c);
+    if (!mpfi_is_inside_si (b, interval)) {
+      print_error (b, interval);
+    }
+
+    mpfr_set_nan (&(interval->right));
+    if (mpfi_is_inside_si (b, interval)) {
+      print_error (b, interval);
+    }
+
+    mpfi_interv_si (interval, a, b);
+    if (c != b && mpfi_is_inside_si (c, interval)) {
+      print_error (c, interval);
+    }
+  }
+
+  mpfi_clear (interval);
+}
+
+int
+main (int argc, char **argv)
+{
+  test_start ();
+
+  check ();
+
+  test_end ();
+
+  return 0;
+}

Added: trunk/mpfi/tests/tis_inside_ui.c
===================================================================
--- trunk/mpfi/tests/tis_inside_ui.c	                        (rev 0)
+++ trunk/mpfi/tests/tis_inside_ui.c	2010-06-24 12:20:35 UTC (rev 326)
@@ -0,0 +1,115 @@
+/* tis_inside_ui.c -- Test mpfi_is_inside_ui.
+
+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"
+
+#include <limits.h>
+#ifndef ULONG_MAX
+# define ULONG_MAX 4294967295
+#endif
+
+#define ORDER(min, max)                         \
+  do {                                          \
+    if (min > max) {                            \
+      unsigned long tmp;                        \
+      tmp = min;                                \
+      min = max;                                \
+      max = tmp;}                               \
+  } while (0)
+
+static void
+print_error (unsigned long x, mpfi_srcptr i)
+{
+  printf ("Error: mpfi_is_inside_ui (x, I) returns %d\nx = %lu\nI = ",
+          mpfi_is_inside_ui (x, i), x);
+  mpfi_out_str (stdout, 10, 0, i);
+  printf ("\n");
+
+  exit (1);
+}
+
+static void
+check ()
+{
+  mpfi_t interval;
+  unsigned long a, b, c;
+  int i;
+
+  i = 1;
+  a = ULONG_MAX;
+  while (a >>= 1) i++;
+
+  mpfi_init2 (interval, i);
+
+  for (i = 0; i <= 1000; ++i) {
+    /* random numbers a < b < c */
+    a = random_ui ();
+    b = random_ui ();
+    c = random_ui ();
+    ORDER (a, b);
+    ORDER (a, c);
+    ORDER (b, c);
+
+    mpfi_interv_ui (interval, b, c);
+    if (a != b && mpfi_is_inside_ui (a, interval)) {
+      print_error (a, interval);
+    }
+
+    mpfr_set_nan (&(interval->left));
+    if (mpfi_is_inside_si (a, interval)) {
+      print_error (a, interval);
+    }
+
+    mpfi_interv_ui (interval, a, c);
+    if (!mpfi_is_inside_ui (b, interval)) {
+      print_error (b, interval);
+    }
+
+    mpfr_set_nan (&(interval->right));
+    if (mpfi_is_inside_si (b, interval)) {
+      print_error (b, interval);
+    }
+
+    mpfi_interv_ui (interval, a, b);
+    if (c != b && mpfi_is_inside_ui (c, interval)) {
+      print_error (c, interval);
+    }
+  }
+
+  mpfi_clear (interval);
+}
+
+int
+main (int argc, char **argv)
+{
+  test_start ();
+
+  check ();
+
+  test_end ();
+
+  return 0;
+}

Added: trunk/mpfi/tests/tis_strictly_inside.c
===================================================================
--- trunk/mpfi/tests/tis_strictly_inside.c	                        (rev 0)
+++ trunk/mpfi/tests/tis_strictly_inside.c	2010-06-24 12:20:35 UTC (rev 326)
@@ -0,0 +1,96 @@
+/* tadd_d.c -- Test mpfi_add_d.
+
+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"
+
+static void
+check_overflow ()
+{
+  mpfr_t max;
+  mpfi_t a;
+  int inexact;
+
+  mpfi_init2 (a, 53);
+  mpfr_init2 (max, 53);
+  mpfr_set_ui (&(a->left), 1, MPFI_RNDD);
+  mpfr_set_inf (max, +1);
+  mpfr_nextbelow (max);
+  mpfr_set (&(a->right), max, MPFI_RNDU);
+
+  inexact = mpfi_add_d (a, a, +1.1);
+
+  if (!mpfr_inf_p (&(a->right))) {
+    printf ("Error: mpfi_add_d does not correctly handle positive "
+            "overflow.\n");
+    exit (1);
+  }
+
+  if (!MPFI_RIGHT_IS_INEXACT (inexact)) {
+    printf ("Error: mpfi_add_d does not return correct value when positive "
+            "overflow.\n");
+    exit (1);
+  }
+
+  mpfr_set_inf (max, -1);
+  mpfr_nextabove (max);
+  mpfr_set (&(a->left), max, MPFI_RNDD);
+  mpfr_set_ui (&(a->right), 1, MPFI_RNDU);
+
+  inexact = mpfi_add_d (a, a, -1.1);
+
+  if (!mpfr_inf_p (&(a->left))) {
+    printf ("Error: mpfi_add_d does not correctly handle negative "
+            "overflow.\n");
+    exit (1);
+  }
+
+  if (!MPFI_LEFT_IS_INEXACT (inexact)) {
+    printf ("Error: mpfi_add_d does not return correct value when negative "
+            "overflow.\n");
+    exit (1);
+  }
+
+  mpfi_clear (a);
+  mpfr_clear (max);
+}
+
+int
+main (int argc, char **argv)
+{
+  struct mpfi_function_t i_add_d;
+
+  mpfi_fun_init_IID (&i_add_d, mpfi_add_d, mpfr_add_d);
+  test_start ();
+
+  check_data (&i_add_d, "add_d.dat");
+  check_random (&i_add_d, 2, 1000, 10);
+  check_overflow ();
+
+  test_end ();
+  mpfi_fun_clear (&i_add_d);
+
+  return 0;
+}




More information about the Mpfi-commits mailing list