I am creating a calculator in Java, and am struggling to come up with a way to handle negative numbers, so far i can parse an expression, for example this:
((4-3)*(4/2))*2
becomes:
[4.0, -3.0, +, 4.0, 2.0, /, *, 2.0, *]
However i don't know how i would deal with expressions containing negatives, such as:
2*(-2-3)
So far i have it so when a negative value is encountered it multiplies the number ahead of it by -1 and adds a + to the end of the list, so the expression becomes this:
[2.0, -2.0, -3.0, +, +, *]
This is causing many errors in my program, can anyone help with a better method to deal with negatives.
Thanks very much for any help
2*(-2-3)
would become2*(0-2-3)
. – sp00m