Maths Expression

Blitz3D Forums/Blitz3D Beginners Area/Maths Expression

PaulJG(Posted 2004) [#1]
Help !.

Whats the maths expression you can use to flip a variable between 0 and 1 everytime you call it ?

I've forgotten.


Floyd(Posted 2004) [#2]
x = 1 - x

or

x = Not x

In general, to flip between values a and b use the sum s

s = a + b

Now to flip x

x = s - x ; if x was one of a or b it is now the other.


PaulJG(Posted 2004) [#3]
Thats the one, thanks Floyd

Just out of interest, I wonder which one would compile to the faster instruction ??


Tiger(Posted 2004) [#4]
or

x=x Xor 1


Zethrax(Posted 2004) [#5]
Another useful value flipping trick is:-

x = -x

to flip the positive/negative sign of x.

Not what you were after but it might come in handy for you sometime.