Sha256: 3a04360f884eaee8aa3ab21fca0b50aa4ab473cab4a059160bf068cf44cf5742

Contents?: true

Size: 959 Bytes

Versions: 2

Compression:

Stored size: 959 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)
            else
              super(x)
            end
          end

          def -(x)
            if x.is_a?(Num)
              _(n - 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)
            else
              super(x)
            end
          end

          def /(x)
            if (n == 0)
              self
            else
              super(x)
            end
          end

          def ^(x)
            if (n == 0) || (n == 1)
              self
            else
              super(x)
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dydx-0.0.2 lib/dydx/algebra/operator/parts/num.rb
dydx-0.0.1 lib/dydx/algebra/operator/parts/num.rb