Fixed wrong overloading.
`float op rational` should return `float`, since float is an inexact
value.
@@ -106,9 +106,8 @@ def Rational(numerator = 0, denominator = 1)
Rational.new(numerator, denominator)
end
-[Fixnum, Float].each do |cls|
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
- cls.instance_exec do
+ Fixnum.instance_exec do
original_operator_name = "__original_operator_#{op}_rational"
alias_method original_operator_name, op
define_method op do |rhs|
@@ -119,5 +118,14 @@ end
end
end
end
+ Float.instance_exec do
+ original_operator_name = "__original_operator_#{op}_rational"
+ alias_method original_operator_name, op
+ define_method op do |rhs|
+ if rhs.is_a? Rational
+ rhs = rhs.to_f
+ end
+ __send__(original_operator_name, rhs)
+ end
end
end
