数值类型比较大小

// 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();
}
posted @ 2023-07-24 10:28  卡尔的思索  阅读(8)  评论(0编辑  收藏  举报