You can write a proposal.
Although I don't see why this couldn't easily be done as a library.
From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> on behalf of John Platts via Std-Proposals <std-proposals@lists.isocpp.org>
Sent: Tuesday, April 8, 2025 1:58:24 PM
To: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
Cc: John Platts <john_platts@hotmail.com>
Subject: [std-proposals] Adding safe saturated floating-point to integer cast to C++26
Introduction:
There is a need to add a safe saturated floating-point integer cast that is guaranteed to saturate a floating-point value to be within the range of the target integer type instead of invoking undefined behavior. There are programming languages other than C++
that already have support for safe saturated floating-point to integer casts, including Java. Some CPU's also have hardware instructions that can do saturated floating-point to integer casts, including ARM CPU's with hardware floating point, AArch64, x86 CPU's
with AVX10.2, and PowerPC.
Motivation and Scope:
This is important as some applications require saturating, well-defined behavior for floating-point to integer conversions that are out of range of the target integer type. In addition, some C++ code is ported to C++ from languages such as Java where floating-point
to integer casts have saturating semantics.
Impact on the standard:
It is possible to implement a safe saturated floating-point-to-integer conversion using pure C++11 code (including constexpr support with C++14 or later), but compiler builtins are needed to allow for additional optimizations beyond what a pure C++11 implementation
would provide (such as vectorization or saturation of out-of-range values).
Design decisions:
The need to add a safe saturated floating-point to integer operation is needed to provide for portable, optimal implementations that provide for additional optimization opportunities, including vectorization and optimization down to a single saturated floating-point
to integer conversion instruction when supported on the target CPU.
The safe saturated floating-point to integer operation is required to have well-defined behavior if no trapping floating-point exceptions are raised, even for NaN input values. The safe saturated floating-point to integer operation is permitted to return an
arbitrary, implementation-defined value for NaN input values, but such an arbitrary value must be treated as a valid result and must not invoke any undefined behavior if a trapping floating-point exception is not raised.