зеркало из https://github.com/github/ruby.git
rational.c: float denom
* rational.c (parse_rat): allow float as a denominator as well as a numerator. [ruby-core:79104] [Bug #13134] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
62fb6147cd
Коммит
a2ac0982cd
13
rational.c
13
rational.c
|
@ -2356,7 +2356,7 @@ static VALUE
|
|||
parse_rat(const char *s, const char *const e, int strict)
|
||||
{
|
||||
int sign;
|
||||
VALUE num, den, ndiv;
|
||||
VALUE num, den, ndiv, ddiv;
|
||||
|
||||
s = skip_ws(s, e);
|
||||
sign = read_sign(&s, e);
|
||||
|
@ -2368,12 +2368,8 @@ parse_rat(const char *s, const char *const e, int strict)
|
|||
nurat_reduce(&num, &ndiv);
|
||||
den = ndiv;
|
||||
if (s < e && *s == '/') {
|
||||
char *t;
|
||||
s++;
|
||||
den = rb_int_parse_cstr(s, e-s, &t, NULL,
|
||||
10, RB_INT_PARSE_UNDERSCORE);
|
||||
s = t;
|
||||
if (NIL_P(den)) {
|
||||
if (!read_num(&s, e, &den, &ddiv)) {
|
||||
if (strict) return Qnil;
|
||||
den = ndiv;
|
||||
}
|
||||
|
@ -2384,8 +2380,11 @@ parse_rat(const char *s, const char *const e, int strict)
|
|||
return Qnil;
|
||||
}
|
||||
else {
|
||||
nurat_reduce(&den, &ddiv);
|
||||
nurat_reduce(&num, &den);
|
||||
den = rb_int_mul(den, ndiv);
|
||||
nurat_reduce(&ndiv, &ddiv);
|
||||
if (ndiv != ONE) den = rb_int_mul(den, ndiv);
|
||||
if (ddiv != ONE) num = rb_int_mul(num, ddiv);
|
||||
}
|
||||
}
|
||||
else if (strict && skip_ws(s, e) != e) {
|
||||
|
|
|
@ -747,6 +747,19 @@ class Rational_Test < Test::Unit::TestCase
|
|||
ng[ 5, 1, '5e_1']
|
||||
ng[50, 1, '5e1_']
|
||||
|
||||
ok[ 50, 33, '5/3.3']
|
||||
ok[ 5, 3, '5/3e0']
|
||||
ok[ 5, 30, '5/3e1']
|
||||
ng[ 5, 3, '5/3._3']
|
||||
ng[ 50, 33, '5/3.3_']
|
||||
ok[500,333, '5/3.3_3']
|
||||
ng[ 5, 3, '5/3e']
|
||||
ng[ 5, 3, '5/3_e']
|
||||
ng[ 5, 3, '5/3e_']
|
||||
ng[ 5, 3, '5/3e_1']
|
||||
ng[ 5, 30, '5/3e1_']
|
||||
ok[ 5, 300000000000, '5/3e1_1']
|
||||
|
||||
ng[0, 1, '']
|
||||
ng[0, 1, ' ']
|
||||
ng[5, 1, "\f\n\r\t\v5\0"]
|
||||
|
@ -756,7 +769,6 @@ class Rational_Test < Test::Unit::TestCase
|
|||
ng[5, 1, '5x']
|
||||
ng[5, 1, '5/_3']
|
||||
ng[5, 3, '5/3_']
|
||||
ng[5, 3, '5/3.3']
|
||||
ng[5, 3, '5/3x']
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче