A function whose value is either one or zero First I apologize in advance for I don't know math's English at all and I haven't done math in almost a decade.
I'm looking for a function whose "domain/ensemble of definition" would be ℝ (or maybe ℤ) and whose "ensemble/domain of variation" would be ℕ{0, 1}
that would look like something this awesome ascii graph...
          ^f(x)
          |          
          |
1________ | __________
0________\./__________>x
         0|
          |
          |
          |

f(x) is always 1, but 0 when x = 0
Actually I need this for programming, I could always find other ways to do what I wanted with booleans so far but it would be much better in most cases to have a simple algebra formula to represent my needs instead.
I just hope it's not too complicated a function to write/understand and that it exists of course. Thanks in advance guys.
 A: Define $f: \mathbb{R} \rightarrow \{0,1\}$ via
$$
f(x) = 
\begin{cases}
0 &\text{ if } x = 0\\
1 &\text{ if } x \neq 0.
\end{cases}
$$
If you are programming, this can be accomplished with a single if-then-else statement. This will surely be more efficient to compute than any "algebra formula" (by which I take you to mean "non-piecewise formula"), since if clauses are built into the language at a very low level.
A: The function $f: \mathbb{R} \rightarrow \{0,1\}$ defined via
$$
f(x) = \lim_{n \rightarrow \infty} \sqrt[n]{x^2}
$$
satisfies $f(0) = 0$ and $f(x) = 1$ for all $x \neq 0$. This is entirely useless for programming, but it is the simplest function I can think of that avoids a piecewise definition.
A: I think that the most compact way to write this is using the Iverson Bracket: 
$f: \mathbb{R} \to \{{0,1}\}$
$$ f(x) = [x \neq 0]$$
A: Well, $f(x)=1-0^x$ will work provided we agree in $0^0=1$.
A: I found this question relevant in social science when you are testing for the effect  of a variable but are uncertain whether it is its mere presence which is significant, or whether the degree of the presence should be used. I have used the following approach in Excel to convert degree of presence ($A_2 \ge 1$) to just presence ($A_2=1$).
The following simple nested 'IF' statement will return 1 if $A_2$ is a positive number, $0$ for $0$, and $-1$ for a negative number.
=IF(A2=0,0,IF(A2>0,1,-1))
