# Calculate Factor thats 1 if value is not 0, and 0 if it is

I don't know if this is the right stackexchange for this question, please tell me/move it if it isn't.

I calculate a value $$x$$ that can be any integer number. I now want to use this variable to get a factor thats $$0$$ if $$x$$ is zero, and 1 if it isn't.

I can easily program this with an if-statement, however due to optimization reasons, I want to get around the if. So I was wondering if there is a mathematical expression that would give me $$fac = 1$$ if $$x\ne0$$ and $$fac=0$$ if $$x = 0$$.

You can set a new variable equal to the floor of $$x/(x-1)$$. ( as long as $$x$$ can't be equal to $$1$$). Alternatively the ceiling of $$x/(x+1)$$ (as long as $$x$$ isn't negative).
• In theory good, but if $x=1$, I have an integer division by zero, which is not good. using $x$ as a floating point number and calculating the floor, gives me for $x=1$ $fac=-2147483684.000$ (I think that's not a math problem but a programming problem). – Fl.pf. Nov 23 '18 at 11:10
• @Fl.pf. My bad, you could do the ceiling of $x/(x+1)$ as long as $x$ can't be negative. – CooperCape Nov 23 '18 at 11:14
• @Fl.pf. That is rather bizarre. $\lceil\frac{x}{x+1}\rceil\equiv 1\ \forall\ x\in\mathbb{Z}^+$ – CooperCape Nov 23 '18 at 11:32