[Gmp-commit] /var/hg/gmp: 3 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sat May 30 05:07:20 UTC 2015


details:   /var/hg/gmp/rev/d8bce5f24ccc
changeset: 16661:d8bce5f24ccc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 30 07:02:48 2015 +0200
description:
mpf/sqrt_ui.c: Special case also for sqrt(1).

details:   /var/hg/gmp/rev/3fc308383836
changeset: 16662:3fc308383836
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 30 07:03:24 2015 +0200
description:
tests/mpf/t-sqrt_ui.c: Test special cases.

details:   /var/hg/gmp/rev/ba77dddd5b1b
changeset: 16663:ba77dddd5b1b
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat May 30 07:07:04 2015 +0200
description:
ChangeLog

diffstat:

 ChangeLog             |   7 +++++--
 mpf/sqrt_ui.c         |  18 +++++++++---------
 tests/mpf/t-sqrt_ui.c |  17 +++++++++++++++--
 3 files changed, 29 insertions(+), 13 deletions(-)

diffs (103 lines):

diff -r 2a5e2ea2e66c -r ba77dddd5b1b ChangeLog
--- a/ChangeLog	Sat May 30 05:52:50 2015 +0200
+++ b/ChangeLog	Sat May 30 07:07:04 2015 +0200
@@ -2,8 +2,11 @@
 
 	* mpf/cmp_ui.c: Use macros, remove branches, correct nails.
 	* mpf/cmp_si.c: Likewise.
-	* mpf/int_p.c: Use a simpler loop to ignore zero limbs.   
-
+	* mpf/int_p.c: Use a simpler loop to ignore zero limbs.
+
+	* mpf/sqrt_ui.c: Special case for sqrt(1).
+	* tests/mpf/t-sqrt_ui.c: Test special cases.
+	
 2015-05-28  Niels Möller  <nisse at lysator.liu.se>
 
 	* doc/gmp.texi (Low-level Functions): Document mpn_divexact_1 and
diff -r 2a5e2ea2e66c -r ba77dddd5b1b mpf/sqrt_ui.c
--- a/mpf/sqrt_ui.c	Sat May 30 05:52:50 2015 +0200
+++ b/mpf/sqrt_ui.c	Sat May 30 07:07:04 2015 +0200
@@ -1,7 +1,7 @@
 /* mpf_sqrt_ui -- Compute the square root of an unsigned integer.
 
-Copyright 1993, 1994, 1996, 2000, 2001, 2004, 2005 Free Software Foundation,
-Inc.
+Copyright 1993, 1994, 1996, 2000, 2001, 2004, 2005, 2015 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -75,16 +75,16 @@
   mp_size_t prec;
   TMP_DECL;
 
-  if (UNLIKELY (u == 0))
+  if (UNLIKELY (u <= 1))
     {
-      r->_mp_size = 0;
-      r->_mp_exp = 0;
+      SIZ (r) = EXP (r) = u;
+      *PTR (r) = u;
       return;
     }
 
   TMP_MARK;
 
-  prec = r->_mp_prec;
+  prec = PREC (r);
   zeros = 2 * prec - 2;
   rsize = zeros + 1 + U2;
 
@@ -101,9 +101,9 @@
   }
 #endif
 
-  mpn_sqrtrem (r->_mp_d, NULL, tp, rsize);
+  mpn_sqrtrem (PTR (r), NULL, tp, rsize);
 
-  r->_mp_size = prec;
-  r->_mp_exp = 1;
+  SIZ (r) = prec;
+  EXP (r) = 1;
   TMP_FREE;
 }
diff -r 2a5e2ea2e66c -r ba77dddd5b1b tests/mpf/t-sqrt_ui.c
--- a/tests/mpf/t-sqrt_ui.c	Sat May 30 05:52:50 2015 +0200
+++ b/tests/mpf/t-sqrt_ui.c	Sat May 30 07:07:04 2015 +0200
@@ -1,6 +1,6 @@
 /* Test mpf_sqrt_ui.
 
-Copyright 2004 Free Software Foundation, Inc.
+Copyright 2004, 2015 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -39,13 +39,26 @@
   mpf_init (s);
   refmpf_set_prec_limbs (s, 2*max_prec+10);
 
+  for (x = 0; x < 2; x++)
+    {
+      mpf_sqrt_ui (r, x);
+      MPF_CHECK_FORMAT (r);
+      if (mpf_cmp_ui (r, x) != 0)
+	{
+	  printf    ("mpf_sqrt_ui wrong for special case:\n");
+          printf    ("  x=%lu\n", x);
+          mpf_trace ("  r", r);
+	  abort ();
+	}
+    }
+
   for (i = 0; i < 50; i++)
     {
       /* input, a random non-zero ulong, exponentially distributed */
       do {
         x = gmp_urandomb_ui (rands,
                              gmp_urandomm_ui (rands, BITS_PER_ULONG) + 1);
-      } while (x == 0);
+      } while (x <= 1);
 
       /* result precision */
       prec = gmp_urandomm_ui (rands, max_prec-min_prec) + min_prec;


More information about the gmp-commit mailing list