Sha256: 89167e1e35c54ec58ae0b7f721bbeaf82641b6f17defb8240623548aaa19e128

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Num
          %w(+ * **).map(&:to_sym).each do |operator|
            define_method(operator) do |x|
              if x.is_a?(Num)
                _(n.send(operator, x.n))
              elsif operator == :+ && x.inverse?(:+) && x.x.is_a?(Num)
                _(n - x.x.n)
              elsif operator == :* && x.inverse?(:*) && x.x.is_a?(Num) && n % x.x.n == 0
                _(n / x.x.n)
              elsif zero?
                case operator
                when :+ then x
                when :* then e0
                when :** then e0
                end
              elsif one?
                case operator
                when :+ then super(x)
                when :* then x
                when :** then e1
                end
              else
                super(x)
              end
            end
          end

          def %(num)
            fail ArgumentError, "#{num} should be Num class object" unless num.is_a?(Num)
            _(n % num.n)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dydx-0.2.7000001 lib/dydx/algebra/operator/parts/num.rb
dydx-0.2.7000000 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.41421 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.412 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.4 lib/dydx/algebra/operator/parts/num.rb