If in between samples you go from above max to below min you'll have both heat and ac on.
The take-away is that like programming lift controllers[0] it's not quite as simple as it might first seem - many many edge cases.
[0] http://play.elevatorsaga.com/ (for example)