Please note that ExpatTech no longer operates regular office hours, meeting is by appointment only. Please call +36306031104 for details.

ExpatTech Techblog

Peter Todd 2009.11.19. 12:21

Flash Cookbook - Tricks - Additive inverse if origo is not zero

The additive inverse is the number, what completes another one to give the additive result zero.

The additive inverse of 5 is -5, as 5 + (-5) = 0.

From another point of view these numbers are symmetrical.

Right. But what if our origo is not zero itself? Let's say, I have 5 as the origo and wanna get the symmetrical number of 7. That is 3. Or I have -90 as the origo and wanna get the symmetrical pair of -87. That is -93.

For this we do the easy math of:

inverse = 2 * origo - number

Check our equation:

2 * 0 - 5 = 0 - 5 = -5, true

2 * 5 - 7 = 10 - 7 = 3, true

2 * (-90) - (-87) = -180 + 87 = -93, true.