aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-14 07:12:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-14 07:12:42 +0000
commit8801161f73398580d54760239553065caf28c9bb (patch)
tree38f15641d13146e01993ba98698834349bb05f6f /sprintf.c
parent280a2005fd680d6d0c24ec14aa1a94641d4ec6ef (diff)
downloadruby-8801161f73398580d54760239553065caf28c9bb.tar.gz
sprintf.c: exact number
* sprintf.c (rb_str_format): format exact number more exactly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/sprintf.c b/sprintf.c
index 84d5fd112b..1984cec805 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1036,13 +1036,19 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
long len, done = 0;
int prefix = 0;
- if (!RB_TYPE_P(val, T_RATIONAL)) {
+ if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) {
+ den = INT2FIX(1);
+ num = val;
+ }
+ else if (RB_TYPE_P(val, T_RATIONAL)) {
+ den = rb_rational_den(val);
+ num = rb_rational_num(val);
+ }
+ else {
nextvalue = val;
goto float_value;
}
if (!(flags&FPREC)) prec = default_float_precision;
- den = rb_rational_den(val);
- num = rb_rational_num(val);
if (FIXNUM_P(num)) {
if ((SIGNED_VALUE)num < 0) {
long n = -FIX2LONG(num);