lib/dydx/algebra.rb in dydx-0.0.9 vs lib/dydx/algebra.rb in dydx-0.1.0

- old
+ new

@@ -11,29 +11,43 @@ module Dydx module Algebra include Set module Set + # TODO: Refactor Symbol.class_eval{ include Operator::Symbol } Fixnum.class_eval do %w(+ - * / ^).each do |operator| define_method(operator) do |g| if g.is_a?(Symbol) || g.is_a?(Formula) || g.is_a?(Base) Num.new(self).send(operator.to_sym, g) - elsif operator == '^' && g.is_a?(Fixnum) - result = 1 - g.times{ result *= self } - result + elsif operator == '^' && g.is_a?(Fixnum) || g.is_a?(Float) + self ** g + elsif operator == '^' && g.is_a?(Num) + self ** g.n else (to_f.send(operator.to_sym, g)).to_i end end end end + Float.class_eval do + %w(^).each do |operator| + define_method(operator) do |g| + if g.is_a?(Fixnum) || g.is_a?(Float) + self ** g + elsif g.is_a?(Num) + self ** g.n + else + Num.new(self).send(operator.to_sym, g) + end + end + end + end class Num; include Operator::Num; end class E; include Operator::General; end class Pi; include Operator::General; end class Log; include Operator::General; end class Sin; include Operator::General; end @@ -51,8 +65,12 @@ elsif x.is_a?(Inverse) && x.operator == operator x.x else Inverse.new(x, operator) end + end + + def -@ + inverse(self, :+) end end end