Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <numeric> | ||
template<class T,class U> constexpr T saturate_cast( U x)noexcept; | (since C++26) | |
Converts the valuex to a value of typeT
, clampingx between the minimum and maximum values of typeT
.
The program is ill-formed if eitherT
orU
is not a signed or unsignedinteger type (includingstandard integer type andextended integer type).
Contents |
x | - | an integer value |
T
. Otherwise,T
, whichever is closer to the value ofx.Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_saturation_arithmetic | 202311L | (C++26) | Saturation arithmetic |
Seelibstdc++ (GCC).
Can be previewed onCompiler Explorer.
#include <cstdint>#include <limits>#include <numeric> int main(){constexprstd::int16_t x1{696}; constexprstd::int8_t x2= std::saturate_cast<std::int8_t>(x1); static_assert(x2==std::numeric_limits<std::int8_t>::max()); constexprstd::uint8_t x3= std::saturate_cast<std::uint8_t>(x1); static_assert(x3==std::numeric_limits<std::uint8_t>::max()); constexprstd::int16_t y1{-696}; constexprstd::int8_t y2= std::saturate_cast<std::int8_t>(y1); static_assert(y2==std::numeric_limits<std::int8_t>::min()); constexprstd::uint8_t y3= std::saturate_cast<std::uint8_t>(y1); static_assert(y3==0);}
(C++20) | reinterpret the object representation of one type as that of another (function template)[edit] |
(C++17) | clamps a value between a pair of boundary values (function template)[edit] |
(C++20) | checks if an integer value is in the range of a given integer type (function template)[edit] |