diff options
author | Torbjorn Granlund <tege@gmplib.org> | 2012-06-01 18:30:10 +0200 |
---|---|---|
committer | Torbjorn Granlund <tege@gmplib.org> | 2012-06-01 18:30:10 +0200 |
commit | b0beb28833e971fbbcde031be534eec2039fa8a2 (patch) | |
tree | ff711a60a0ee1bda5d26389d5f8ed31364b69cd8 /mpz | |
parent | a5c663c7d0b05d7764e5a8fec1f0ade6729239d6 (diff) | |
download | gmp-b0beb28833e971fbbcde031be534eec2039fa8a2.tar.gz |
Don't strip leading zeros since current mpn_get_str won't generate any.
Misc streamlining.
Diffstat (limited to 'mpz')
-rw-r--r-- | mpz/get_str.c | 19 | ||||
-rw-r--r-- | mpz/out_str.c | 29 |
2 files changed, 13 insertions, 35 deletions
diff --git a/mpz/get_str.c b/mpz/get_str.c index 486b88b95..c70119409 100644 --- a/mpz/get_str.c +++ b/mpz/get_str.c @@ -4,7 +4,7 @@ result. If STRING is not NULL, the caller must ensure enough space is available to store the result. -Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005 Free Software +Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -32,7 +32,6 @@ mpz_get_str (char *res_str, int base, mpz_srcptr x) { mp_ptr xp; mp_size_t x_size = SIZ (x); - char *str; char *return_str; size_t str_size; size_t alloc_size = 0; @@ -83,26 +82,16 @@ mpz_get_str (char *res_str, int base, mpz_srcptr x) xp = PTR (x); if (! POW2_P (base)) { - xp = TMP_ALLOC_LIMBS (x_size + 1); /* +1 in case x_size==0 */ + xp = TMP_ALLOC_LIMBS (x_size); MPN_COPY (xp, PTR (x), x_size); } str_size = mpn_get_str ((unsigned char *) res_str, base, xp, x_size); ASSERT (alloc_size == 0 || str_size <= alloc_size - (SIZ(x) < 0)); - /* might have a leading zero, skip it */ - str = res_str; - if (*res_str == 0 && str_size != 1) - { - str_size--; - str++; - ASSERT (*str != 0); /* at most one leading zero */ - } - - /* Convert result to printable chars, and move down if there was a leading - zero. */ + /* Convert result to printable chars. */ for (i = 0; i < str_size; i++) - res_str[i] = num_to_text[(int) str[i]]; + res_str[i] = num_to_text[(int) res_str[i]]; res_str[str_size] = 0; TMP_FREE; diff --git a/mpz/out_str.c b/mpz/out_str.c index 2e8e933ed..b4341ac91 100644 --- a/mpz/out_str.c +++ b/mpz/out_str.c @@ -1,8 +1,8 @@ /* mpz_out_str(stream, base, integer) -- Output to STREAM the multi prec. integer INTEGER in base BASE. -Copyright 1991, 1993, 1994, 1996, 2001, 2005, 2011 Free Software Foundation, -Inc. +Copyright 1991, 1993, 1994, 1996, 2001, 2005, 2011, 2012 Free Software +Foundation, Inc. This file is part of the GNU MP Library. @@ -61,12 +61,6 @@ mpz_out_str (FILE *stream, int base, mpz_srcptr x) num_to_text = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } - if (x_size == 0) - { - fputc ('0', stream); - return ferror (stream) ? 0 : 1; - } - written = 0; if (x_size < 0) @@ -82,21 +76,16 @@ mpz_out_str (FILE *stream, int base, mpz_srcptr x) str_size += 3; str = (unsigned char *) TMP_ALLOC (str_size); - /* Move the number to convert into temporary space, since mpn_get_str - clobbers its argument + needs one extra high limb.... */ - xp = TMP_ALLOC_LIMBS (x_size + 1); - MPN_COPY (xp, PTR (x), x_size); - - str_size = mpn_get_str (str, base, xp, x_size); - - /* mpn_get_str might make some leading zeros. Skip them. */ - while (*str == 0) + xp = PTR (x); + if (! POW2_P (base)) { - str_size--; - str++; + xp = TMP_ALLOC_LIMBS (x_size); + MPN_COPY (xp, PTR (x), x_size); } - /* Translate to printable chars. */ + str_size = mpn_get_str (str, base, xp, x_size); + + /* Convert result to printable chars. */ for (i = 0; i < str_size; i++) str[i] = num_to_text[str[i]]; str[str_size] = 0; |