Add abs_cap function to deal with numerical problems.