you can use std::abs() here to make it more general. fabs is limited to certain float or double.