[Gmp-commit] /var/hg/gmp-6.1: Return negative value for negative input.

mercurial at gmplib.org mercurial at gmplib.org
Tue Mar 7 15:59:53 UTC 2017


details:   /var/hg/gmp-6.1/rev/93fdbf79860b
changeset: 16969:93fdbf79860b
user:      Torbjorn Granlund <tg at gmplib.org>
date:      Tue Mar 07 16:59:30 2017 +0100
description:
Return negative value for negative input.

diffstat:

 mpf/get_d_2exp.c |  16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diffs (51 lines):

diff -r 7b8e56bbdeaa -r 93fdbf79860b mpf/get_d_2exp.c
--- a/mpf/get_d_2exp.c	Fri Dec 16 16:45:01 2016 +0100
+++ b/mpf/get_d_2exp.c	Tue Mar 07 16:59:30 2017 +0100
@@ -1,6 +1,6 @@
 /* double mpf_get_d_2exp (signed long int *exp, mpf_t src).
 
-Copyright 2001-2004 Free Software Foundation, Inc.
+Copyright 2001-2004, 2017 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -28,23 +28,22 @@
 GNU Lesser General Public License along with the GNU MP Library.  If not,
 see https://www.gnu.org/licenses/.  */
 
-#include "gmp.h"
 #include "gmp-impl.h"
 #include "longlong.h"
 
 
 double
-mpf_get_d_2exp (signed long int *exp2, mpf_srcptr src)
+mpf_get_d_2exp (signed long int *expptr, mpf_srcptr src)
 {
   mp_size_t size, abs_size;
   mp_srcptr ptr;
   int cnt;
-  long exp;
+  double d;
 
   size = SIZ(src);
   if (UNLIKELY (size == 0))
     {
-      *exp2 = 0;
+      *expptr = 0;
       return 0.0;
     }
 
@@ -53,9 +52,8 @@
   count_leading_zeros (cnt, ptr[abs_size - 1]);
   cnt -= GMP_NAIL_BITS;
 
-  exp = EXP(src) * GMP_NUMB_BITS - cnt;
-  *exp2 = exp;
+  *expptr = EXP(src) * GMP_NUMB_BITS - cnt;
 
-  return mpn_get_d (ptr, abs_size, (mp_size_t) 0,
-                    (long) - (abs_size * GMP_NUMB_BITS - cnt));
+  d = mpn_get_d (ptr, abs_size, 0, -(abs_size * GMP_NUMB_BITS - cnt));
+  return size >= 0 ? d : -d;
 }


More information about the gmp-commit mailing list