can you comment that you are encoding the fact that all these numbers are >= 0? This looks strange at first sight. Also, there is a lot of code duplication here. Do you not trust the inliner to write one function and call it repeatedly?