optimize unary minus for constants
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user