optimize unary minus for constants
This commit is contained in:
@@ -183,9 +183,13 @@ module RubyAlgebra
|
||||
when :positive
|
||||
out_stack.push a
|
||||
when :negative
|
||||
if a.type == :constant
|
||||
out_stack.push Constant.new(-a.value)
|
||||
else
|
||||
out_stack.push Multiplication.new(Constant.new(-1), a)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self._parse_op_prio(op_token)
|
||||
case op_token.op
|
||||
|
||||
Reference in New Issue
Block a user