diff --git a/lib/ruby_algebra/parser.rb b/lib/ruby_algebra/parser.rb index 98f2a70..05c8086 100644 --- a/lib/ruby_algebra/parser.rb +++ b/lib/ruby_algebra/parser.rb @@ -183,7 +183,11 @@ module RubyAlgebra when :positive out_stack.push a when :negative - out_stack.push Multiplication.new(Constant.new(-1), a) + if a.type == :constant + out_stack.push Constant.new(-a.value) + else + out_stack.push Multiplication.new(Constant.new(-1), a) + end end end