aboutsummaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-03-17 22:52:04 +0200
committerArnold D. Robbins <arnold@skeeve.com>2015-03-17 22:52:04 +0200
commit69b9c6bec08738933d79010ad8c9347e36d19bed (patch)
treee3d2790fb4a77b871234ba15784bd4e1e057981e /profile.c
parent8fc0c719fc910d6931d267b5437cef9048e5a9b0 (diff)
parentcd2ff61aaf4938092517880ad7655828d99a3cb9 (diff)
downloadegawk-69b9c6bec08738933d79010ad8c9347e36d19bed.tar.gz
egawk-69b9c6bec08738933d79010ad8c9347e36d19bed.tar.bz2
egawk-69b9c6bec08738933d79010ad8c9347e36d19bed.zip
Merge branch 'master' into feature/regex-type
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/profile.c b/profile.c
index 2cb9e159..3e9ef783 100644
--- a/profile.c
+++ b/profile.c
@@ -1390,16 +1390,30 @@ pp_number(NODE *n)
{
#define PP_PRECISION 6
char *str;
+ size_t count;
- emalloc(str, char *, PP_PRECISION + 10, "pp_number");
#ifdef HAVE_MPFR
- if (is_mpg_float(n))
- mpfr_sprintf(str, "%0.*R*g", PP_PRECISION, ROUND_MODE, n->mpg_numbr);
- else if (is_mpg_integer(n))
+ if (is_mpg_float(n)) {
+ count = mpfr_get_prec(n->mpg_numbr) / 3; /* ~ 3.22 binary digits per decimal digit */
+ emalloc(str, char *, count, "pp_number");
+ /*
+ * 3/2015: Format string used to be "%0.*R*g". That padded
+ * with leading zeros. But it doesn't do that for regular
+ * numbers in the non-MPFR case.
+ */
+ mpfr_sprintf(str, "%.*R*g", PP_PRECISION, ROUND_MODE, n->mpg_numbr);
+ } else if (is_mpg_integer(n)) {
+ count = mpz_sizeinbase(n->mpg_i, 10) + 2; /* +1 for sign, +1 for NUL at end */
+ emalloc(str, char *, count, "pp_number");
mpfr_sprintf(str, "%Zd", n->mpg_i);
- else
+ } else
#endif
- sprintf(str, "%0.*g", PP_PRECISION, n->numbr);
+ {
+ count = PP_PRECISION + 10;
+ emalloc(str, char *, count, "pp_number");
+ sprintf(str, "%0.*g", PP_PRECISION, n->numbr);
+ }
+
return str;
#undef PP_PRECISION
}