summaryrefslogtreecommitdiff
path: root/mpz
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2020-03-15 19:44:09 +0100
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2020-03-15 19:44:09 +0100
commit610f37abf2e1b3082b8f9b5d6789d042c09e9e23 (patch)
treeb8cff6a023d1a04cfb1909b1e0b30cf6c39e3f7f /mpz
parentc07e396277eab29d644a37f02b2fdcfbc4b68b1c (diff)
downloadgmp-610f37abf2e1b3082b8f9b5d6789d042c09e9e23.tar.gz
mpz/root.c: Move a branch out of the likely path.
Diffstat (limited to 'mpz')
-rw-r--r--mpz/root.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/mpz/root.c b/mpz/root.c
index 7119bbc3a..7c8d368c3 100644
--- a/mpz/root.c
+++ b/mpz/root.c
@@ -1,7 +1,7 @@
/* mpz_root(root, u, nth) -- Set ROOT to floor(U^(1/nth)).
Return an indication if the result is exact.
-Copyright 1999-2003, 2005, 2012 Free Software Foundation, Inc.
+Copyright 1999-2003, 2005, 2012, 2020 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -45,10 +45,17 @@ mpz_root (mpz_ptr root, mpz_srcptr u, unsigned long int nth)
if (UNLIKELY (us < 0 && (nth & 1) == 0))
SQRT_OF_NEGATIVE;
- /* root extraction interpreted as c^(1/nth) means a zeroth root should
- provoke a divide by zero, do this even if c==0 */
- if (UNLIKELY (nth == 0))
- DIVIDE_BY_ZERO;
+ if (UNLIKELY (nth <= 1))
+ {
+ /* root extraction interpreted as c^(1/nth) means a zeroth root should
+ provoke a divide by zero, do this even if c==0 */
+ if (UNLIKELY (nth == 0))
+ DIVIDE_BY_ZERO;
+ /* nth == 1 */
+ if (root != NULL && u != root)
+ mpz_set (root, u);
+ return 1; /* exact result */
+ }
if (us == 0)
{
@@ -69,16 +76,7 @@ mpz_root (mpz_ptr root, mpz_srcptr u, unsigned long int nth)
rootp = TMP_ALLOC_LIMBS (rootn);
up = PTR(u);
-
- if (nth == 1)
- {
- MPN_COPY (rootp, up, un);
- remn = 0;
- }
- else
- {
- remn = mpn_rootrem (rootp, NULL, up, un, (mp_limb_t) nth);
- }
+ remn = mpn_rootrem (rootp, NULL, up, un, (mp_limb_t) nth);
if (root != NULL)
{