Not entirely sure if this is correct, but can't you simply use the cmath library and use the abs() function?