Same thing as lower in the text: use std::min and std::max.