diff --git a/content/atomic-floating-min-max.md b/content/atomic-floating-min-max.md new file mode 100644 index 0000000..6b300c9 --- /dev/null +++ b/content/atomic-floating-min-max.md @@ -0,0 +1,35 @@ +--- +execute: true +--- + +## What It Does + +The `fetch_max`, `fetch_min`, `fetch_fmaximum`, `fetch_fminimum`, `fetch_fmaximum_num`, and `fetch_fminimum_num` +member functions for `std::atomic` and `std::atomic_ref` make it possible to atomically +take the minimum or maximum of two floating-point numbers. +`std::fmaximum`, `std::fmaximum_num`, `std::fminimum`, and `std::fminimum_num` +are also added to ``, providing non-atomic counterparts. + +## Why It Matters + +By utilizing hardware support, +floating-point minimum and maximum can have much better performance than existing code +which uses `compare_exchange_weak` in a loop, +especially with high contention. +The new `` functions imported from C23 are also generally useful, +and implement operations from the ISO/IEC 60559 standard. + +## Example + +```cpp +#include +#include + +std::atomic x = 0.5; + +int main() { + std::println("{}", x.fetch_max(0)); // prints 0.5, no update + std::println("{}", x.fetch_max(1)); // prints 0.5, x = 1 + std::println("{}", x.load()); // prints 1 +} +``` diff --git a/features_cpp26.yaml b/features_cpp26.yaml index a358780..61a2465 100644 --- a/features_cpp26.yaml +++ b/features_cpp26.yaml @@ -1487,6 +1487,8 @@ features: - desc: "Atomic floating-point min/max" paper: P3008 + summary: "Adds atomic minimum/maximum operations between floating-point types, as well as non-atomic `` functions." + content: atomic-float-min-max.md lib: true ftm: - name: __cpp_lib_atomic_min_max