Hello Yves,
Your description isn't complete and could be either hysteresis or deadband (which is what GerdW has provided some psuedo code for). Hysteresis typically has to have some "memory", and there are many different forms of hysteresis. There are plenty of rescources online describe hysteresis functions - both graphically and mathematically.
Just did a quick search - and came up with this - looks a fairly complex function - depends if you need something smooth:
http://revue.elth.pub.ro/upload/66469907Motoasca.pdf
Maybe you can cope with a simpler hysteresis function that just has straight lines!