Sha256: 8d3b0ca41e1edae55a64a25d34e9cda7971feef9cca1151cdea581a4c60323a1

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Num
          def +(x)
            if n == 0
              x
            elsif x.is_a?(Num)
              _(n + x.n)
            elsif x.subtrahend? && x.x.is_a?(Num)
              _(n - x.x.n)
            else
              super(x)
            end
          end

          def *(x)
            if n == 0
              self
            elsif n == 1
              x
            elsif x.is_a?(Num)
              _(n * x.n)
            elsif x.divisor? && x.x.is_a?(Num)
              _(n / x.x.n)
            else
              super(x)
            end
          end

          def ^(x)
            if (n == 0) || (n == 1)
              self
            elsif x.is_a?(Num)
              _(n ^ x.n)
            else
              super(x)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dydx-0.0.7 lib/dydx/algebra/operator/parts/num.rb
dydx-0.0.6 lib/dydx/algebra/operator/parts/num.rb
dydx-0.0.5 lib/dydx/algebra/operator/parts/num.rb