The formula is easy & widely available when the values are positive, but tricky to track down when negative. The solution is to use ‘ABS’, choosing whichever of these formulae is most convenient for your situation:

|margin| = 1 - 1 / (1 + |markup|)
|markup| = 1 / (1 - |margin|) - 1
|markup| = 1 / n <=> |margin| = 1 / (n + 1)
1 / |margin| = 1 + 1 / |markup|

This essentially boils down to… when you’re given a negative value, make it positive, proceed with your calculation as usual, then make the answer also negative.