Fixed wrong overloading.
`float op rational` should return `float`, since float is an inexact
value.
MODIFY
mrbgems/mruby-rational/mrblib/rational.rb
mrbgems/mruby-rational/mrblib/rational.rb
@@ -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

Fixed wrong overloading.

`float op rational` should return `float`, since float is an inexact
value.