[Gmp-commit] /var/hg/gmp: Better fix for the mpf/reuse overflow issue, by Tor...

mercurial at gmplib.org mercurial at gmplib.org
Tue Oct 8 21:55:00 CEST 2013


details:   /var/hg/gmp/rev/d1876b5a236e
changeset: 16037:d1876b5a236e
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Tue Oct 08 21:54:32 2013 +0200
description:
Better fix for the mpf/reuse overflow issue, by Torbjorn.

diffstat:

 ChangeLog         |   6 ++++++
 tests/mpf/reuse.c |  20 +++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diffs (63 lines):

diff -r eb8af78993e0 -r d1876b5a236e ChangeLog
--- a/ChangeLog	Tue Oct 08 19:15:05 2013 +0200
+++ b/ChangeLog	Tue Oct 08 21:54:32 2013 +0200
@@ -1,3 +1,9 @@
+2013-10-08  Torbjorn Granlund  <tege at gmplib.org>
+	    Marc Glisse  <marc.glisse at inria.fr>
+
+	* tests/mpf/reuse.c (main): Compare addresses instead of names.
+	Use larger numbers for exponents.
+
 2013-10-08  Marc Glisse  <marc.glisse at inria.fr>
 
 	* doc/mdate-sh, doc/texinfo.tex, install-sh, missing, ylwrap: Remove.
diff -r eb8af78993e0 -r d1876b5a236e tests/mpf/reuse.c
--- a/tests/mpf/reuse.c	Tue Oct 08 19:15:05 2013 +0200
+++ b/tests/mpf/reuse.c	Tue Oct 08 21:54:32 2013 +0200
@@ -66,8 +66,6 @@
 
 typedef void (*dsi_func) (mpf_ptr, mpf_srcptr, unsigned long int);
 
-/* The order matters. For mpf_mul_2exp and the functions after it,
-   we use a small number in the tests since it represents an exponent.  */
 dsi_func dsi_funcs[] =
 {
   mpf_div_ui, mpf_add_ui, mpf_mul_ui, mpf_sub_ui,
@@ -150,18 +148,22 @@
       in2i = urandom ();
       for (i = 0; i < sizeof (dsi_funcs) / sizeof (dsi_func); i++)
 	{
+	  unsigned long this_in2i = in2i;
+
 	  /* Don't divide by 0.  */
-	  if (strcmp (dsi_func_names[i], "mpf_div_ui") == 0 && in2i == 0)
+	  if (dsi_funcs[i] == mpf_div_ui && this_in2i == 0)
 	    continue;
 
-	  /* Avoid overflows in the exponent.  */
-	  if (strcmp (dsi_func_names[i], "mpf_mul_2exp") == 0)
-	    in2i %= 64;
+	  /* Avoid overflow/underflow in the exponent.  */
+	  if (dsi_funcs[i] == mpf_mul_2exp || dsi_funcs[i] == mpf_div_2exp)
+	    this_in2i %= 0x100000;
+	  else if (dsi_funcs[i] == mpf_pow_ui)
+	    this_in2i %= 0x1000;
 
-	  (dsi_funcs[i]) (res1, in1, in2i);
+	  (dsi_funcs[i]) (res1, in1, this_in2i);
 
 	  mpf_set (out1, in1);
-	  (dsi_funcs[i]) (out1, out1, in2i);
+	  (dsi_funcs[i]) (out1, out1, this_in2i);
 	  mpf_set (res2, out1);
 
 	  if (mpf_cmp (res1, res2) != 0)
@@ -172,7 +174,7 @@
       for (i = 0; i < sizeof (dis_funcs) / sizeof (dis_func); i++)
 	{
 	  /* Don't divide by 0.  */
-	  if (strcmp (dis_func_names[i], "mpf_ui_div") == 0
+	  if (dis_funcs[i] == mpf_ui_div
 	      && mpf_cmp_ui (in2, 0) == 0)
 	    continue;
 


More information about the gmp-commit mailing list