Renaming saturation arithmetic functions
- Document number:
- P4052R0
- Date:
2026-03-13 - Audience:
- LEWG
- Project:
- ISO/IEC 14882 Programming Languages — C++, ISO/IEC JTC1/SC22/WG21
- Reply-to:
- Jan Schultke <janschultke@gmail.com>
- Corentin Jabot <corentin.jabot@gmail.com>
- GitHub Issue:
- wg21.link/P4052/github
- Source:
- github.com/eisenwave/cpp-proposals/blob/master/src/rename-sat.cow
Contents
Introduction
Arguments against sat
Broader design context
Proposal
Wording
References
1. Introduction
NB comment [FR-026-265] states the following:
The names
,add_sat ,sub_sat etc are rather confusing and nondescriptmul_sat Proposed change: Rename to
,saturating_add ,saturating_sub ,saturating_mul OR Rename tosaturating_div /add_saturate /sub_saturate /mul_saturate .div_saturate
[P0543R3] provides the following rationale for the status quo:
Naming
Considerations:
- These are basic low-level operations. Names should be short.
/add /sub /mul are common abbreviation for the corresponding arithmetic operations.div Options (only showing the operation "saturated addition"):
,addsat : not easily readablesatadd ,saturated_add : too longadd_saturated : more readable due to underscoresat_add : more readable due to underscore, precedence in OpenCLadd_sat The last choice is taken.
1.1. Arguments against sat
The NB comment is right in the sense that to a novice,
the abbreviation does not have obvious meaning.
It can also be argued not to match the recommendation of the [LEWGDesignGuidelines]:
Avoid abbreviations except for common words:
,_ptr , etc. (apply common sense).std
While conciseness is generally desirable in numeric context, it may have been given too much importance in [P0543R3]. Several arguments speak against the status quo:
-
The status quo is not internally consistent.
has a heavily abbreviated name, whereasadd_sat is unabbreviated. By comparison, there is a Rust cratesaturate_cast saturating_cast , which is internally consistent withsaturating_add in the Rust standard library. -
Many other libraries do not abbreviate
:sat Library Function Rust Standard Library saturating_add Java, Guava Core Libraries saturatedAdd C#, .NET AddSaturate C++, LLVM SaturatingAdd -
At the time of writing,
GitHub code search
yields the following results:
IfSearch Reg. Exp. # Files \ b saturating_add \ b 204K \ b add_sat \ b 71.9K \ b sat_add \ b 3.1K \ b add_saturate \ b 1.1K \ b saturated_add \ b 738 \ b add_saturated \ b 656 \ b saturate_add \ b 248 \ b add_saturating \ b 189 \ b add_saturation \ b 143 \ b saturation_add \ b 55 must be abbreviated because the alternative issat too long
, why is the unabbreviatedsaturating_add almost three times as popular? -
Both
(18 characters) andstd :: add_sat ( x , y )
(25 characters) are verbose, compared tostd :: saturating_add ( x , y )
(5 characters). If large amounts of operations need to be made saturating, the user should create a class template with saturatingx + y .operator +
1.2. Broader design context
The naming of saturation arithmetic functions is hugely important because it essentially
sets the naming policy for all future arithmetic variations
.
For example, Rust supports a large amount of variations of multiplication:
| Rust function | Meaning | C++ counterpart |
|---|---|---|
|
Returns product clamped to numeric range of type | C++26 |
|
Returns product, as well as indicating overflow |
[P3161R4] ,C++26 and C23: ,GCC:
|
|
Returns low and high bits of product | [P3161R4] |
|
Wrapping multiplication (including for signed types) | multiplication |
|
Returns containing product,or empty result on overflow |
N/A |
It is plausible that given time, some or all of these variations of multiplication could be available in C++. We thus need a sustainable naming scheme that can handle all such variations.
as the widening variation of .
Note that the naming scheme here deliberately imitates that of ;
it is not convergent evolution
.
2. Proposal
The existing functions in [numeric.sat] should all be renamed to follow a
naming scheme,
including .
This should be done for the following reasons:
- The meaning of
is more obvious than forsaturating .sat - The design is familiar to Rust users, and a similar Rust-based approach can be taken for many more operation variations.
-
The naming scheme is internally consistent,
unlike
vs.add_sat .saturate_cast -
is the most common naming scheme. Any other option (saturating_ op ,sat , etc.) yields fewer results in GitHub code search.saturate
Furthermore, LEWG should commit to the Rust naming scheme for future proposals,
such as [P3161R4] and [P3642R4],
which propose and , respectively.
3. Wording
The changes are relative to [N5032].
Bump the feature-test macro in [version.syn] as follows:
could be ,
with being ill-formed.
Change [numeric.ops.overview] as follows:
Rename the declarations in [numeric.sat] analogously.