mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 04:24:04 +02:00
rational.c: convert a numerator to rational before calling fdiv in Kernel.Rational() (#3702)
This makes `Rational(BigDecimal(1), 60) == Rational(1, 60)`. [Bug #16518]
This commit is contained in:
parent
52c630da00
commit
69837229d7
Notes:
git
2020-10-26 18:43:56 +09:00
Merged-By: mrkn <mrkn@ruby-lang.org>
2 changed files with 17 additions and 1 deletions
|
@ -165,6 +165,14 @@ class Rational_Test < Test::Unit::TestCase
|
|||
if (1.0/0).infinite?
|
||||
assert_raise(FloatDomainError){Rational(1.0/0)}
|
||||
end
|
||||
|
||||
bug16518 = "[ruby-core:96942] [Bug #16518]"
|
||||
cls = Class.new(Numeric) do
|
||||
def /(y); 42; end
|
||||
def to_r; 1r; end
|
||||
def to_int; 1; end
|
||||
end
|
||||
assert_equal(1/2r, Rational(cls.new, 2))
|
||||
end
|
||||
|
||||
def test_attr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue