summaryrefslogtreecommitdiff
path: root/mpf
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2006-07-12 18:51:46 +0200
committertege <tege@gmplib.org>2006-07-12 18:51:46 +0200
commit9fa6f932240e735e0a8929de10f9fc9cd4969bc2 (patch)
tree8ff3266bc5e14dc055e045a205f6e88e484c06a9 /mpf
parentf6fb31124d771519648e1de674e3bf46199f43cc (diff)
downloadgmp-9fa6f932240e735e0a8929de10f9fc9cd4969bc2.tar.gz
Avoid copying result when not needed. Misc cleanups.
Diffstat (limited to 'mpf')
-rw-r--r--mpf/get_str.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/mpf/get_str.c b/mpf/get_str.c
index e98397050..ca282ceb5 100644
--- a/mpf/get_str.c
+++ b/mpf/get_str.c
@@ -1,10 +1,10 @@
/* mpf_get_str (digit_ptr, exp, base, n_digits, a) -- Convert the floating
- point number A to a base BASE number and store N_DIGITS raw digits at
- DIGIT_PTR, and the base BASE exponent in the word pointed to by EXP. For
- example, the number 3.1416 would be returned as "31416" in DIGIT_PTR and
- 1 in EXP.
+ point number A to a base BASE number and store N_DIGITS raw digits at
+ DIGIT_PTR, and the base BASE exponent in the word pointed to by EXP. For
+ example, the number 3.1416 would be returned as "31416" in DIGIT_PTR and
+ 1 in EXP.
-Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005 Free
+Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2002, 2003, 2005, 2006 Free
Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -24,18 +24,16 @@ along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
-#include <stdlib.h> /* for NULL */
+#include <stdio.h> /* for NULL */
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h" /* for count_leading_zeros */
/* Could use some more work.
- 1. Don't unconditionally allocate temps on the stack.
- 2. Make one temp alloc block, and split it manually.
- 3. Allocation is excessive. Try to combine areas. Perhaps use result
+ 1. Allocation is excessive. Try to combine areas. Perhaps use result
string area for temp limb space?
- 4. We generate up to two limbs worth of digits. This is because we don't
+ 2. We generate up to two limbs of extra digits. This is because we don't
check the exact number of bits in the input operand, and from that
compute an accurate exponent (variable e in the code). It would be
cleaner and probably somewhat faster to change this.
@@ -97,12 +95,16 @@ mpn_pow_1_highpart (mp_ptr rp, mp_size_t *ignp,
if (rn > prec)
{
+ ASSERT (rn == prec + 1);
+
ign += rn - prec;
rp += rn - prec;
rn = prec;
}
- MPN_COPY_INCR (passed_rp, rp + off, rn);
+ /* With somewhat less than 50% probability, we can skip this copy. */
+ if (passed_rp != rp + off)
+ MPN_COPY_INCR (passed_rp, rp + off, rn);
*ignp = ign;
return rn;
}