It looks like the bug in the original code is just `if (xmax > xabs) xmax = xabs;` which should be `xmax < xabs`