[libc][NFC] Use STL case for limits

Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion.

Differential Revision: https://reviews.llvm.org/D130762

GitOrigin-RevId: 91eb0b6584e06f898ad1994962a0bc73937c7f49
diff --git a/src/__support/CPP/CMakeLists.txt b/src/__support/CPP/CMakeLists.txt
index 7172dae..4897154 100644
--- a/src/__support/CPP/CMakeLists.txt
+++ b/src/__support/CPP/CMakeLists.txt
@@ -47,7 +47,7 @@
 add_header_library(
   limits
   HDRS
-    Limits.h
+    limits.h
   DEPENDS
     .uint
 )
diff --git a/src/__support/CPP/Limits.h b/src/__support/CPP/limits.h
similarity index 79%
rename from src/__support/CPP/Limits.h
rename to src/__support/CPP/limits.h
index 8f27d07..1a6f3a0 100644
--- a/src/__support/CPP/Limits.h
+++ b/src/__support/CPP/limits.h
@@ -16,60 +16,60 @@
 namespace __llvm_libc {
 namespace cpp {
 
-template <class T> class NumericLimits {
+template <class T> class numeric_limits {
 public:
   static constexpr T max();
   static constexpr T min();
 };
 
-// TODO: Add NumericLimits specializations as needed for new types.
+// TODO: Add numeric_limits specializations as needed for new types.
 
-template <> class NumericLimits<int> {
+template <> class numeric_limits<int> {
 public:
   static constexpr int max() { return INT_MAX; }
   static constexpr int min() { return INT_MIN; }
 };
-template <> class NumericLimits<unsigned int> {
+template <> class numeric_limits<unsigned int> {
 public:
   static constexpr unsigned int max() { return UINT_MAX; }
   static constexpr unsigned int min() { return 0; }
 };
-template <> class NumericLimits<long> {
+template <> class numeric_limits<long> {
 public:
   static constexpr long max() { return LONG_MAX; }
   static constexpr long min() { return LONG_MIN; }
 };
-template <> class NumericLimits<unsigned long> {
+template <> class numeric_limits<unsigned long> {
 public:
   static constexpr unsigned long max() { return ULONG_MAX; }
   static constexpr unsigned long min() { return 0; }
 };
-template <> class NumericLimits<long long> {
+template <> class numeric_limits<long long> {
 public:
   static constexpr long long max() { return LLONG_MAX; }
   static constexpr long long min() { return LLONG_MIN; }
 };
-template <> class NumericLimits<unsigned long long> {
+template <> class numeric_limits<unsigned long long> {
 public:
   static constexpr unsigned long long max() { return ULLONG_MAX; }
   static constexpr unsigned long long min() { return 0; }
 };
-template <> class NumericLimits<short> {
+template <> class numeric_limits<short> {
 public:
   static constexpr short max() { return SHRT_MAX; }
   static constexpr short min() { return SHRT_MIN; }
 };
-template <> class NumericLimits<unsigned short> {
+template <> class numeric_limits<unsigned short> {
 public:
   static constexpr unsigned short max() { return USHRT_MAX; }
   static constexpr unsigned short min() { return 0; }
 };
-template <> class NumericLimits<char> {
+template <> class numeric_limits<char> {
 public:
   static constexpr char max() { return CHAR_MAX; }
   static constexpr char min() { return CHAR_MIN; }
 };
-template <> class NumericLimits<unsigned char> {
+template <> class numeric_limits<unsigned char> {
 public:
   static constexpr unsigned char max() { return UCHAR_MAX; }
   static constexpr unsigned char min() { return 0; }
@@ -79,7 +79,7 @@
 //    provides limits of UInt128.
 // 2. On platforms where UInt128 resolves to __uint128_t, this specialization
 //    allows us to unittest UInt<128>.
-template <> class NumericLimits<UInt<128>> {
+template <> class numeric_limits<UInt<128>> {
 public:
   static constexpr UInt<128> max() { return ~UInt<128>(0); }
   static constexpr UInt<128> min() { return 0; }
@@ -87,7 +87,7 @@
 #ifdef __SIZEOF_INT128__
 // On platform where UInt128 resolves to __uint128_t, this specialization
 // provides the limits of UInt128.
-template <> class NumericLimits<__uint128_t> {
+template <> class numeric_limits<__uint128_t> {
 public:
   static constexpr __uint128_t max() { return ~__uint128_t(0); }
   static constexpr __uint128_t min() { return 0; }
diff --git a/src/__support/FPUtil/generic/FMod.h b/src/__support/FPUtil/generic/FMod.h
index ea52020..a922253 100644
--- a/src/__support/FPUtil/generic/FMod.h
+++ b/src/__support/FPUtil/generic/FMod.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H
 
-#include "src/__support/CPP/Limits.h"
+#include "src/__support/CPP/limits.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
@@ -190,7 +190,7 @@
   inline constexpr static intU_t execute(int exp_diff, int sides_zeroes_count,
                                          intU_t m_x, intU_t m_y) {
     if (exp_diff > sides_zeroes_count) {
-      intU_t inv_hy = (cpp::NumericLimits<intU_t>::max() / m_y);
+      intU_t inv_hy = (cpp::numeric_limits<intU_t>::max() / m_y);
       while (exp_diff > sides_zeroes_count) {
         exp_diff -= sides_zeroes_count;
         intU_t hd =
diff --git a/src/__support/str_to_float.h b/src/__support/str_to_float.h
index 2348603..3b043ec 100644
--- a/src/__support/str_to_float.h
+++ b/src/__support/str_to_float.h
@@ -9,8 +9,8 @@
 #ifndef LIBC_SRC_SUPPORT_STR_TO_FLOAT_H
 #define LIBC_SRC_SUPPORT_STR_TO_FLOAT_H
 
-#include "src/__support/CPP/Limits.h"
 #include "src/__support/CPP/UInt128.h"
+#include "src/__support/CPP/limits.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/builtin_wrappers.h"
 #include "src/__support/ctype_utils.h"
@@ -738,7 +738,7 @@
 
   // The loop fills the mantissa with as many digits as it can hold
   const BitsType bitstype_max_div_by_base =
-      __llvm_libc::cpp::NumericLimits<BitsType>::max() / BASE;
+      cpp::numeric_limits<BitsType>::max() / BASE;
   while (true) {
     if (isdigit(*src)) {
       uint32_t digit = *src - '0';
@@ -828,7 +828,7 @@
 
   // The loop fills the mantissa with as many digits as it can hold
   const BitsType bitstype_max_div_by_base =
-      __llvm_libc::cpp::NumericLimits<BitsType>::max() / BASE;
+      cpp::numeric_limits<BitsType>::max() / BASE;
   while (true) {
     if (isalnum(*src)) {
       uint32_t digit = b36_char_to_int(*src);
diff --git a/src/__support/str_to_integer.h b/src/__support/str_to_integer.h
index c3505c3..3f3349d 100644
--- a/src/__support/str_to_integer.h
+++ b/src/__support/str_to_integer.h
@@ -9,7 +9,7 @@
 #ifndef LIBC_SRC_SUPPORT_STR_TO_INTEGER_H
 #define LIBC_SRC_SUPPORT_STR_TO_INTEGER_H
 
-#include "src/__support/CPP/Limits.h"
+#include "src/__support/CPP/limits.h"
 #include "src/__support/ctype_utils.h"
 #include <errno.h>
 #include <limits.h>
@@ -92,15 +92,14 @@
     src = src + 2;
   }
 
-  constexpr bool IS_UNSIGNED = (__llvm_libc::cpp::NumericLimits<T>::min() == 0);
+  constexpr bool IS_UNSIGNED = (cpp::numeric_limits<T>::min() == 0);
   const bool is_positive = (result_sign == '+');
   unsigned long long constexpr NEGATIVE_MAX =
-      !IS_UNSIGNED ? static_cast<unsigned long long>(
-                         __llvm_libc::cpp::NumericLimits<T>::max()) +
-                         1
-                   : __llvm_libc::cpp::NumericLimits<T>::max();
+      !IS_UNSIGNED
+          ? static_cast<unsigned long long>(cpp::numeric_limits<T>::max()) + 1
+          : cpp::numeric_limits<T>::max();
   unsigned long long const abs_max =
-      (is_positive ? __llvm_libc::cpp::NumericLimits<T>::max() : NEGATIVE_MAX);
+      (is_positive ? cpp::numeric_limits<T>::max() : NEGATIVE_MAX);
   unsigned long long const abs_max_div_by_base = abs_max / base;
   while (isalnum(*src)) {
     int cur_digit = b36_char_to_int(*src);
@@ -137,9 +136,9 @@
 
   if (result == abs_max) {
     if (is_positive || IS_UNSIGNED)
-      return __llvm_libc::cpp::NumericLimits<T>::max();
+      return cpp::numeric_limits<T>::max();
     else // T is signed and there is a negative overflow
-      return __llvm_libc::cpp::NumericLimits<T>::min();
+      return cpp::numeric_limits<T>::min();
   }
 
   return is_positive ? static_cast<T>(result) : -static_cast<T>(result);
diff --git a/src/stdio/printf_core/converter_utils.h b/src/stdio/printf_core/converter_utils.h
index 85895f1..ec605ab 100644
--- a/src/stdio/printf_core/converter_utils.h
+++ b/src/stdio/printf_core/converter_utils.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CONVERTER_UTILS_H
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_CONVERTER_UTILS_H
 
-#include "src/__support/CPP/Limits.h"
+#include "src/__support/CPP/limits.h"
 #include "src/stdio/printf_core/core_structs.h"
 
 #include <inttypes.h>
@@ -21,23 +21,23 @@
 inline uintmax_t apply_length_modifier(uintmax_t num, LengthModifier lm) {
   switch (lm) {
   case LengthModifier::none:
-    return num & cpp::NumericLimits<unsigned int>::max();
+    return num & cpp::numeric_limits<unsigned int>::max();
   case LengthModifier::l:
-    return num & cpp::NumericLimits<unsigned long>::max();
+    return num & cpp::numeric_limits<unsigned long>::max();
   case LengthModifier::ll:
   case LengthModifier::L:
-    return num & cpp::NumericLimits<unsigned long long>::max();
+    return num & cpp::numeric_limits<unsigned long long>::max();
   case LengthModifier::h:
-    return num & cpp::NumericLimits<unsigned short>::max();
+    return num & cpp::numeric_limits<unsigned short>::max();
   case LengthModifier::hh:
-    return num & cpp::NumericLimits<unsigned char>::max();
+    return num & cpp::numeric_limits<unsigned char>::max();
   case LengthModifier::z:
-    return num & cpp::NumericLimits<size_t>::max();
+    return num & cpp::numeric_limits<size_t>::max();
   case LengthModifier::t:
     // We don't have unsigned ptrdiff so uintptr_t is used, since we need an
     // unsigned type and ptrdiff is usually the same size as a pointer.
     static_assert(sizeof(ptrdiff_t) == sizeof(uintptr_t));
-    return num & cpp::NumericLimits<uintptr_t>::max();
+    return num & cpp::numeric_limits<uintptr_t>::max();
   case LengthModifier::j:
     return num; // j is intmax, so no mask is necessary.
   }
diff --git a/src/stdio/printf_core/write_int_converter.h b/src/stdio/printf_core/write_int_converter.h
index 5baebd9..b270127 100644
--- a/src/stdio/printf_core/write_int_converter.h
+++ b/src/stdio/printf_core/write_int_converter.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H
 #define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_WRITE_INT_CONVERTER_H
 
-#include "src/__support/CPP/Limits.h"
+#include "src/__support/CPP/limits.h"
 #include "src/stdio/printf_core/core_structs.h"
 #include "src/stdio/printf_core/writer.h"
 
diff --git a/test/src/__support/CPP/limits_test.cpp b/test/src/__support/CPP/limits_test.cpp
index b55823f..82ce0b8 100644
--- a/test/src/__support/CPP/limits_test.cpp
+++ b/test/src/__support/CPP/limits_test.cpp
@@ -6,39 +6,40 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/Limits.h"
 #include "src/__support/CPP/UInt.h"
+#include "src/__support/CPP/limits.h"
 #include "utils/UnitTest/Test.h"
 
+namespace __llvm_libc {
+
 // This just checks against the C spec, almost all implementations will surpass
 // this.
 TEST(LlvmLibcLimitsTest, LimitsFollowSpec) {
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::max(), INT_MAX);
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<int>::min(), INT_MIN);
+  ASSERT_EQ(cpp::numeric_limits<int>::max(), INT_MAX);
+  ASSERT_EQ(cpp::numeric_limits<int>::min(), INT_MIN);
 
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned int>::max(), UINT_MAX);
+  ASSERT_EQ(cpp::numeric_limits<unsigned int>::max(), UINT_MAX);
 
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::max(), LONG_MAX);
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long>::min(), LONG_MIN);
+  ASSERT_EQ(cpp::numeric_limits<long>::max(), LONG_MAX);
+  ASSERT_EQ(cpp::numeric_limits<long>::min(), LONG_MIN);
 
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long>::max(), ULONG_MAX);
+  ASSERT_EQ(cpp::numeric_limits<unsigned long>::max(), ULONG_MAX);
 
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::max(), LLONG_MAX);
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<long long>::min(), LLONG_MIN);
+  ASSERT_EQ(cpp::numeric_limits<long long>::max(), LLONG_MAX);
+  ASSERT_EQ(cpp::numeric_limits<long long>::min(), LLONG_MIN);
 
-  ASSERT_EQ(__llvm_libc::cpp::NumericLimits<unsigned long long>::max(),
-            ULLONG_MAX);
+  ASSERT_EQ(cpp::numeric_limits<unsigned long long>::max(), ULLONG_MAX);
 }
 
 TEST(LlvmLibcLimitsTest, UInt128Limits) {
-  auto umax128 =
-      __llvm_libc::cpp::NumericLimits<__llvm_libc::cpp::UInt<128>>::max();
-  auto umax64 = __llvm_libc::cpp::UInt<128>(
-      __llvm_libc::cpp::NumericLimits<uint64_t>::max());
+  auto umax128 = cpp::numeric_limits<__llvm_libc::cpp::UInt<128>>::max();
+  auto umax64 =
+      __llvm_libc::cpp::UInt<128>(cpp::numeric_limits<uint64_t>::max());
   EXPECT_GT(umax128, umax64);
   ASSERT_EQ(~__llvm_libc::cpp::UInt<128>(0), umax128);
 #ifdef __SIZEOF_INT128__
-  ASSERT_EQ(~__uint128_t(0),
-            __llvm_libc::cpp::NumericLimits<__uint128_t>::max());
+  ASSERT_EQ(~__uint128_t(0), cpp::numeric_limits<__uint128_t>::max());
 #endif
 }
+
+} // namespace __llvm_libc