use std::max, std::min instead of macro, fix compile warning.