From d3184e4a6d8b85a22dd46f4e2909492a0a08cab1 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 19 Mar 2021 10:30:16 +0900 Subject: complex.c: overhaul complex operators. - define `MRB_TT_COMPLEX` - change object structure (`struct RComplex`) - add memory management for `MRB_TT_COMPLEX` - avoid operator overloading as much as possible - as a result, performance improved a log - should work with and without `Rational` defined --- mrbgems/mruby-complex/mrblib/complex.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'mrbgems/mruby-complex/mrblib/complex.rb') diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb index f54151c7b..0b5fc8f73 100644 --- a/mrbgems/mruby-complex/mrblib/complex.rb +++ b/mrbgems/mruby-complex/mrblib/complex.rb @@ -81,7 +81,7 @@ class Complex < Numeric alias_method :conj, :conjugate def fdiv(numeric) - Complex(real.to_f / numeric, imaginary.to_f / numeric) + Complex(real / numeric, imaginary / numeric) end def polar @@ -108,21 +108,6 @@ class Complex < Numeric alias_method :imag, :imaginary - [Integer, Float].each do |cls| - cls.class_eval do - [:+, :-, :*, :/, :==].each do |op| - original_operator_name = :"__original_operator_#{op}_complex" - alias_method original_operator_name, op - define_method op do |rhs| - if rhs.is_a? Complex - Complex(self).__send__(op, rhs) - else - __send__(original_operator_name, rhs) - end - end - end - end - end Numeric.class_eval do def i Complex(0, self) -- cgit v1.2.3