[libcxx-commits] [libcxx] [libcxx] p3008 atomic fp min/max (PR #186716)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 21 07:29:01 PDT 2026


================
@@ -0,0 +1,112 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_ATOMICS_ATOMIC_FETCH_FMAX_HELPER_H
+#define TEST_STD_ATOMICS_ATOMIC_FETCH_FMAX_HELPER_H
+
+#include <cassert>
+#include <cmath>
+#include <limits>
+#include <type_traits>
+
+#include "test_macros.h"
+
+// Test fetch_max for floating-point types
+// NOTE: NaN handling and signed zero comparison (-0.0 vs +0.0) are unspecified
+// LoadOp: () -> T - reads current value
+// StoreOp: (T) -> void - stores a value
+// MaxOp: (T, memory_order) -> T - performs fetch_max operation
+template <class T, class LoadOp, class StoreOp, class MaxOp>
+void test_fetch_fmax(LoadOp load, StoreOp store, MaxOp max_op) {
+  static_assert(std::is_floating_point_v<T>);
+
+  constexpr T inf = std::numeric_limits<T>::infinity();
+
+  // Test basic fetch_max (update to larger value)
+  {
+    store(T(10.0));
+    T old = max_op(T(20.0), std::memory_order_seq_cst);
----------------
huixie90 wrote:

we usually test the return type to match exact T instead of convertible to T

```
std::same_as<T> decltype(auto) x = ...;
```

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


More information about the libcxx-commits mailing list