Conditional constraint formulation [duplicate]

How can I create constraints to make sure $$x=1$$ if $$k\geq 0$$ and $$x=0$$ if $$k<0$$, where $$x\in \{0,1\}$$ and $$k\in \mathbb{R}$$?

Here is my attempt: \label{cons:1} \begin{aligned} k\leq Mx \end{aligned}

Considering $$M$$ as the big-M, the above constraint makes sure $$x=1$$ if $$k>0$$. Surely, it is missing all other components.

• Have you checked some of the questions posted on the site? Such as here or here?
– EhsanK
Jul 1 '19 at 18:49
• maybe you edit your original question so that it contains this more concise statement. And as @EhsanK says, there may be an answer here already (namely, that strict inequalities require an epsilon to model). Jul 1 '19 at 18:55
• @EhsanK, I have just checked those posts. Jul 1 '19 at 19:14
• @MarcoLübbecke, do you mean I can introduce $k+\epsilon \leq Mx$ to make sure $x=1$ if $k\geq 0$ ? Then, what is the next constraint to ensure $x=0$ when $k<0$? Jul 1 '19 at 19:17
• I feel the next constraint is $k\geq -M(1-x)$. Please correct me if I am wrong. Jul 1 '19 at 19:22