summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-14 07:12:42 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-14 07:12:42 (GMT)
commit1301d1f5bccc10daf93c816ef4e177776d0668de (patch)
tree38f15641d13146e01993ba98698834349bb05f6f /sprintf.c
parented11f4b4b5fbc3ae059cab582f054518f60f9e74 (diff)
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 84d5fd1..1984cec 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);