# Function such that $f(x) = -1$ for $x < 0,$ and $f(x)=1$ for $x > 0$?

What is a function to returns $-1$ if number is negative, $1$ if positive, and zero if number is equal to 0?

for example:

$$f(-8) = -1$$ $$f(8) = 1$$ $$f(0) = 0$$

for $$x < 0$$ maybe?

$$f(x) = (-x-(-x-1))\cdot-1$$

• The Heaviside step function almost satisfies your requirements. – David Simmons May 19 '13 at 20:08
• Not exactly. By using it, $$H(-3) = 0,H(3) = 1$$ – Assembly May 19 '13 at 21:19
• The idea, I think, is to use $2H(x) - 1$. But it's a much better idea (IMO) to just say what you mean, like in Trevor's answer. – Ben Millwood May 19 '13 at 21:33

This function is the $\text{sgn}$ (sign) function. You can write it as $$\text{sgn}(x)=\begin{cases}\frac x{|x|} &x\neq 0\\ 0 & x=0\end{cases}$$

• Nice, and quick! $\;+ \;\ddot\smile$ – amWhy May 19 '13 at 20:10
• Thanks very much. What do you think about my first solution too bad or acceptable to a begginer to math? I will to accept your question. – Assembly May 19 '13 at 20:16
• I'm sorry but I still can't give my up vote because I'm < 15 reputation. – Assembly May 19 '13 at 20:17
• It's a bit hard to understand your suggestion, because there is no $=$ symbol (you may want to use parenthesis for the $-1$ and \cdot for the multiplication). But the problem is that the function is not continuous, so you cannot represent it as a multiplication and addition like that, because that would be continuous. Note that it simplifies to $-(-x+(x+1))=-(x-x+1)=-1$, which is not the function you want. – Asaf Karagila May 19 '13 at 20:26
• @AsafKaragila:If I increment my thanks-counter to you,an integer overflow may happens. Better say nothing! joke answer. Thank you again. – Assembly May 19 '13 at 21:04

As pointed out in the other answers, this function goes by various names. However, if your question is just "what is such a function?" then the answer is that it is the function you have defined. Note that

$$f(x) = \begin{cases} -1 & \text{if } x<0\\ 1 & \text{if } x>0\\ 0 & \text{if } x=0 \end{cases}$$

is a perfectly valid definition of a function on $\mathbb{R}$, because it uniquely specifies what $f(x)$ is for every real number $x$. Definitions by cases are just as good as any other kind of definition, and I think it is confusing to hide the distinction between the three cases (negative, positive, and zero) by some algebraic trick.

• I have a question. In the Asaf Karagila's answer,he show the function and an equation to how should x be computed. In your answer,you show also the result what value of x according to condition. How they are this called? function definition and declaration or something like this? – Assembly May 19 '13 at 20:43
• @Assembly, whereas I presented a slightly more compact form (which lumped the non-zero cases together) that required a small computation, Trevor is using constant functions and simply defined by three cases rather than two cases like myself. This is "definition by cases", and as long the cases are non-overlapping the definition is fine. – Asaf Karagila May 19 '13 at 20:58
• @AsafKaragila: Thanks again. – Assembly May 19 '13 at 21:02
• (Aside: the cases should be complete as well as non-overlapping! That is to say, you should make sure you don't accidentally specify a value for any particular $x$ twice, and you should make sure you specify at least one value for each $x$.) – Ben Millwood May 19 '13 at 21:35
• @TrevorWilson: Thanks very much – Assembly May 19 '13 at 21:39

Your function is exactly the signum function