summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-18 08:06:37 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-18 08:06:37 (GMT)
commit22892ca6c2f68df005622b2e4daf246a649a4d1b (patch)
tree9ab7e1ce14bd0675a918d612be297116f4b6cba1 /sprintf.c
parent17677647917a7d343808b65a976698c8dbc68ef2 (diff)
sprintf.c: remove magic numbers
* sprintf.c (rb_str_format): name default float precision and remove unused initial value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/sprintf.c b/sprintf.c
index c4f304f..69920c6 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -455,6 +455,7 @@ rb_f_sprintf(int argc, const VALUE *argv)
VALUE
rb_str_format(int argc, const VALUE *argv, VALUE fmt)
{
+ enum {default_float_precision = 6};
rb_encoding *enc;
const char *p, *end;
char *buf;
@@ -1030,7 +1031,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
{
VALUE val = GETARG();
double fval;
- int i, need = 6;
+ int i, need;
char fbuf[32];
fval = RFLOAT_VALUE(rb_Float(val));
@@ -1082,7 +1083,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if (i > 0)
need = BIT_DIGITS(i);
}
- need += (flags&FPREC) ? prec : 6;
+ need += (flags&FPREC) ? prec : default_float_precision;
if ((flags&FWIDTH) && need < width)
need = width;
need += 20;