[flang] [llvm] [Flang] Introduce *Value classes with unittests (PR #216958)

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 05:13:09 PDT 2026


================
@@ -305,4 +305,69 @@ template <int BITS>
 using HostSignedIntType = typename HostSignedIntTypeHelper<BITS>::type;
 
 } // namespace Fortran::common
+
+namespace std {
+// Specializing std::numeric_limits is an intended extension point for
+// user-defined type.
+template <> class numeric_limits<Fortran::common::UnsignedInt128> {
+public:
+  using T = Fortran::common::UnsignedInt128;
+
+  static constexpr bool is_specialized{true};
+  static constexpr bool is_signed{false};
+  static constexpr bool is_integer{true};
+
+  static constexpr T min() { return T{0, 0}; }
+  static constexpr T max() { return T{UINT64_MAX, UINT64_MAX}; }
+};
+
+template <> class numeric_limits<Fortran::common::SignedInt128> {
+public:
+  using T = Fortran::common::SignedInt128;
+
+  static constexpr bool is_specialized{true};
+  static constexpr bool is_signed{true};
+  static constexpr bool is_integer{true};
+
+  static constexpr T min() {
+    return T{static_cast<std::uint64_t>(INT64_MIN), 0};
+  }
+  static constexpr T max() {
+    return T{static_cast<std::uint64_t>(INT64_MAX), UINT64_MAX};
+  }
+};
----------------
Meinersbur wrote:

I intentionally only implemented only those memembers that are used. Adding more would be dead code and know knowing what their right value should be, e.g. `std::numeric_limits<uint128_t>::epsilon` which the C++ standard describes as "Meaningful for all floating-point types". Before I specify something wrong I would rather not specify anything; it can be added when the need arises.

I will add `lower()`.

https://github.com/llvm/llvm-project/pull/216958


More information about the llvm-commits mailing list