summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-complex/mrblib/complex.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-03-19 10:30:16 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-03-19 10:37:10 +0900
commitd3184e4a6d8b85a22dd46f4e2909492a0a08cab1 (patch)
treeb45f9be65a970d80d4b60401e44d053f3b78b394 /mrbgems/mruby-complex/mrblib/complex.rb
parent08f9d5bab5092fe1193dd100765079e3e4d746b9 (diff)
downloadmruby-d3184e4a6d8b85a22dd46f4e2909492a0a08cab1.tar.gz
mruby-d3184e4a6d8b85a22dd46f4e2909492a0a08cab1.zip
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
Diffstat (limited to 'mrbgems/mruby-complex/mrblib/complex.rb')
-rw-r--r--mrbgems/mruby-complex/mrblib/complex.rb17
1 files changed, 1 insertions, 16 deletions
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)