зеркало из https://github.com/github/ruby.git
sprintf.c: Rational f by generic Integer functions
* sprintf.c (rb_str_format): convert Rational to floating point format by using gereric Integer functions, not by methods which can be overwritten. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3ce3e196ac
Коммит
ee2f3c6def
|
@ -1,3 +1,9 @@
|
|||
Sun Mar 27 12:13:37 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* sprintf.c (rb_str_format): convert Rational to floating point
|
||||
format by using gereric Integer functions, not by methods which
|
||||
can be overwritten.
|
||||
|
||||
Sat Mar 26 10:55:12 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* numeric.c (rb_int2str): conversion function to String for
|
||||
|
|
17
sprintf.c
17
sprintf.c
|
@ -1056,22 +1056,19 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||
sign = -1;
|
||||
}
|
||||
}
|
||||
else if (rb_num_negative_p(num)) {
|
||||
else if (BIGNUM_NEGATIVE_P(num)) {
|
||||
sign = -1;
|
||||
num = rb_funcallv(num, idUMinus, 0, 0);
|
||||
num = rb_big_uminus(num);
|
||||
}
|
||||
if (den != INT2FIX(1) || prec > 1) {
|
||||
const ID idDiv = rb_intern("div");
|
||||
VALUE p10 = rb_int_positive_pow(10, prec);
|
||||
VALUE den_2 = rb_funcall(den, idDiv, 1, INT2FIX(2));
|
||||
num = rb_funcallv(num, '*', 1, &p10);
|
||||
num = rb_funcallv(num, '+', 1, &den_2);
|
||||
num = rb_funcallv(num, idDiv, 1, &den);
|
||||
if (den != INT2FIX(1)) {
|
||||
num = rb_int_mul(num, rb_int_positive_pow(10, prec));
|
||||
num = rb_int_plus(num, rb_int_idiv(den, INT2FIX(2)));
|
||||
num = rb_int_idiv(num, den);
|
||||
}
|
||||
else if (prec >= 0) {
|
||||
zero = prec;
|
||||
}
|
||||
val = rb_obj_as_string(num);
|
||||
val = rb_int2str(num, 10);
|
||||
len = RSTRING_LEN(val) + zero;
|
||||
if (prec >= len) ++len; /* integer part 0 */
|
||||
if (sign || (flags&FSPACE)) ++len;
|
||||
|
|
Загрузка…
Ссылка в новой задаче