Using FP package to compute sum breaks: FP error: UPN stack is empty!

The problem can be easily fixed by adding extra parentheses in your \AddToTotal command:

\FPeval\TempTotal{(\Total)+\NewAmount}%  <-- extra parentheses around \Total

Without the parentheses, a negative \Total is expanded as is, giving something like -6000+-1000 where the first expression is interpreted as a subtraction rather than a negative number. fp then produces an empty stack error because the second operand for that subtraction is missing on the internal stack.

To fix that you have to give it a hint that the negative number is a single atom by putting a pair of parentheses around it. You now correctly get:

enter image description here

That alternative version also seems to work:

\FPeval\TempTotal{0+\Total+\NewAmount}

Not sure why the parsing works differently at the start of the expression than in the middle.

Tags:

Fp