something strange here.
if (clamptozero) { f = std::max(0.0f, f) would be ok. Also I would made f const.