[libcxx-commits] [libcxx] [libc++][math] Add `constexpr` to comparison functions (PR #210075)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 22 02:03:43 PDT 2026
================
@@ -0,0 +1,92 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// bool isgreater(floating-point-type x, floating-point-type y); // constexpr since C++23
+
+#include <cassert>
+#include <cmath>
+#include <limits>
+#include <type_traits>
+
+#include "test_macros.h"
+#include "type_algorithms.h"
+
+struct TestFloat {
+ template <class T>
+ static TEST_CONSTEXPR_CXX23 bool test() {
+ assert(std::isgreater(std::numeric_limits<T>::max(), T(0)));
+ assert(!std::isgreater(T(0), std::numeric_limits<T>::max()));
+ assert(!std::isgreater(std::numeric_limits<T>::max(), std::numeric_limits<T>::max()));
+
+ assert(std::isgreater(std::numeric_limits<T>::infinity(), std::numeric_limits<T>::max()));
+ assert(!std::isgreater(-std::numeric_limits<T>::infinity(), std::numeric_limits<T>::lowest()));
+ assert(!std::isgreater(std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()));
+
+ assert(!std::isgreater(std::numeric_limits<T>::quiet_NaN(), T(0)));
+ assert(!std::isgreater(T(0), std::numeric_limits<T>::quiet_NaN()));
+ assert(!std::isgreater(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN()));
+ assert(!std::isgreater(std::numeric_limits<T>::signaling_NaN(), T(0)));
+
+ return true;
+ }
+
+ template <class T>
+ TEST_CONSTEXPR_CXX23 void operator()() {
+ test<T>();
+#if TEST_STD_VER >= 23
+ static_assert(test<T>());
+#endif
+ }
+};
+
+struct TestInt {
+ template <class T>
+ static TEST_CONSTEXPR_CXX23 bool test() {
+ assert(std::isgreater(std::numeric_limits<T>::max(), T(0)));
+ assert(!std::isgreater(T(0), std::numeric_limits<T>::max()));
+ assert(!std::isgreater(std::numeric_limits<T>::max(), std::numeric_limits<T>::max()));
+
+ assert(!std::isgreater(T(1), T(1)));
+ assert(!std::isgreater(std::numeric_limits<T>::lowest(), T(0)));
+
+ if (std::is_signed<T>::value) {
+ assert(std::isgreater(T(-1), std::numeric_limits<T>::lowest()));
+ assert(!std::isgreater(std::numeric_limits<T>::lowest(), T(-1)));
+ }
+
+ return true;
+ }
+
+ template <class T>
+ TEST_CONSTEXPR_CXX23 void operator()() {
+ test<T>();
+#if TEST_STD_VER >= 23
+ static_assert(test<T>());
+#endif
+ }
----------------
philnik777 wrote:
Why is this here and not in `main` like usually?
https://github.com/llvm/llvm-project/pull/210075
More information about the libcxx-commits
mailing list