数值类型比较大小

发布时间 2023-07-24 10:31:09作者: 卡尔的思索
// Integral type equal
template <typename T>
typename std::enable_if<std::is_integral<T>::value, bool>::type Equal(
    const T& lhs, const T& rhs) {
  return lhs == rhs;
}

// Floating point type equal
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value, bool>::type Equal(
    const T& lhs, const T& rhs) {
  return std::fabs(lhs - rhs) < std::numeric_limits<T>::epsilon();
}