mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
cdhash_cmp: rational literals with fractions
Nobu kindly pointed out that rational literals can have fractions.
This commit is contained in:
parent
2bc293e899
commit
d0e6c6e682
Notes:
git
2021-05-12 10:31:14 +09:00
2 changed files with 7 additions and 2 deletions
|
@ -2006,8 +2006,9 @@ cdhash_cmp(VALUE val, VALUE lit)
|
||||||
return rb_float_cmp(lit, val);
|
return rb_float_cmp(lit, val);
|
||||||
}
|
}
|
||||||
else if (tlit == T_RATIONAL) {
|
else if (tlit == T_RATIONAL) {
|
||||||
/* Rational literals don't have fractions. */
|
const struct RRational *dat1 = RRATIONAL(val);
|
||||||
return cdhash_cmp(val, rb_rational_num(lit));
|
const struct RRational *dat2 = RRATIONAL(lit);
|
||||||
|
return (dat1->num == dat2->num) && (dat1->den == dat2->den);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
UNREACHABLE_RETURN(-1);
|
UNREACHABLE_RETURN(-1);
|
||||||
|
|
|
@ -835,6 +835,10 @@ class Rational_Test < Test::Unit::TestCase
|
||||||
n = case 1 when 2r then false else true end
|
n = case 1 when 2r then false else true end
|
||||||
assert_equal(n, true, '[ruby-core:103759] [Bug #17854]')
|
assert_equal(n, true, '[ruby-core:103759] [Bug #17854]')
|
||||||
RUBY
|
RUBY
|
||||||
|
assert_separately([], <<-RUBY)
|
||||||
|
n = case 3/2r when 1.5r then true else false end
|
||||||
|
assert_equal(n, true, '[ruby-core:103759] [Bug #17854]')
|
||||||
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_Rational_with_invalid_exception
|
def test_Rational_with_invalid_exception
|
||||||
|
|
Loading…
Reference in a new issue