summaryrefslogtreecommitdiff
path: root/mpf
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2008-11-09 01:27:47 +0100
committerTorbjorn Granlund <tege@gmplib.org>2008-11-09 01:27:47 +0100
commitbdf95a8312bd0b740ee82f45751e3a00bd4df9d3 (patch)
tree3e8d604557f6494d1af55697c711dc65d01dffab /mpf
parent40641505f5176e246101212f23118050e386b48a (diff)
downloadgmp-bdf95a8312bd0b740ee82f45751e3a00bd4df9d3.tar.gz
Allocate mantissa space based on mantissa size, not on destination
variable space. Default 'base' before letting exp_base inherit it.
Diffstat (limited to 'mpf')
-rw-r--r--mpf/set_str.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/mpf/set_str.c b/mpf/set_str.c
index 7615fb63a..0417303a3 100644
--- a/mpf/set_str.c
+++ b/mpf/set_str.c
@@ -137,7 +137,12 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
c = (unsigned char) *++str;
}
+ /* Default base to decimal. */
+ if (base == 0)
+ base = 10;
+
exp_base = base;
+
if (base < 0)
{
exp_base = 10;
@@ -165,10 +170,6 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
return -1;
}
- /* Default base to decimal. */
- if (base == 0)
- base = 10;
-
/* Locate exponent part of the input. Look from the right of the string,
since the exponent is usually a lot shorter than the mantissa. */
expptr = NULL;
@@ -249,7 +250,8 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
str_size = n_chars_needed;
#endif
- ma = 2 * (prec + 1);
+ ma = (((mp_size_t) (str_size / mp_bases[base].chars_per_bit_exactly))
+ / GMP_NUMB_BITS + 2);
mp = TMP_ALLOC_LIMBS (ma);
mn = mpn_set_str (mp, (unsigned char *) begs, str_size, base);