|
9621 | 9621 | constexpr T midpoint(T a, T b) noexcept;
|
9622 | 9622 | template<class T>
|
9623 | 9623 | constexpr T* midpoint(T* a, T* b);
|
| 9624 | + |
| 9625 | + // \ref{numeric.sat}, saturation arithmetic |
| 9626 | + template<class T> |
| 9627 | + constexpr T add_sat(T x, T y) noexcept; // freestanding |
| 9628 | + template<class T> |
| 9629 | + constexpr T sub_sat(T x, T y) noexcept; // freestanding |
| 9630 | + template<class T> |
| 9631 | + constexpr T mul_sat(T x, T y) noexcept; // freestanding |
| 9632 | + template<class T> |
| 9633 | + constexpr T div_sat(T x, T y) noexcept; // freestanding |
| 9634 | + template<class T, class U> |
| 9635 | + constexpr T saturate_cast(U x) noexcept; // freestanding |
9624 | 9636 | }
|
9625 | 9637 | \end{codeblock}
|
9626 | 9638 |
|
@@ -10755,6 +10767,119 @@
|
10755 | 10767 | where the result of the division is truncated towards zero.
|
10756 | 10768 | \end{itemdescr}
|
10757 | 10769 |
|
| 10770 | +\rSec2[numeric.sat]{Saturation arithmetic} |
| 10771 | + |
| 10772 | +\rSec3[numeric.sat.func]{Arithmetic functions} |
| 10773 | + |
| 10774 | +\pnum |
| 10775 | +\begin{note} |
| 10776 | +In the following descriptions, an arithmetic operation |
| 10777 | +is performed as a mathematical operation with infinite range and then |
| 10778 | +it is determined whether the mathematical result fits into the result type. |
| 10779 | +\end{note} |
| 10780 | + |
| 10781 | +\indexlibraryglobal{add_sat}% |
| 10782 | +\begin{itemdecl} |
| 10783 | +template<class T> |
| 10784 | + constexpr T add_sat(T x, T y) noexcept; |
| 10785 | +\end{itemdecl} |
| 10786 | + |
| 10787 | +\begin{itemdescr} |
| 10788 | +\pnum |
| 10789 | +\constraints |
| 10790 | +\tcode{T} is a signed or unsigned integer type\iref{basic.fundamental}. |
| 10791 | + |
| 10792 | +\pnum |
| 10793 | +\returns |
| 10794 | +If $\tcode{x} + \tcode{y}$ is representable as a value of type \tcode{T}, $\tcode{x} + \tcode{y}$; |
| 10795 | +otherwise, either the largest or smallest representable value of type \tcode{T}, |
| 10796 | +whichever is closer to the value of $\tcode{x} + \tcode{y}$. |
| 10797 | +\end{itemdescr} |
| 10798 | + |
| 10799 | +\indexlibraryglobal{sub_sat}% |
| 10800 | +\begin{itemdecl} |
| 10801 | +template<class T> |
| 10802 | + constexpr T sub_sat(T x, T y) noexcept; |
| 10803 | +\end{itemdecl} |
| 10804 | + |
| 10805 | +\begin{itemdescr} |
| 10806 | +\pnum |
| 10807 | +\constraints |
| 10808 | +\tcode{T} is a signed or unsigned integer type\iref{basic.fundamental}. |
| 10809 | + |
| 10810 | +\pnum |
| 10811 | +\returns |
| 10812 | +If $\tcode{x} - \tcode{y}$ is representable as a value of type \tcode{T}, $\tcode{x} - \tcode{y}$; |
| 10813 | +otherwise, either the largest or smallest representable value of type \tcode{T}, |
| 10814 | +whichever is closer to the value of $\tcode{x} - \tcode{y}$. |
| 10815 | +\end{itemdescr} |
| 10816 | + |
| 10817 | +\indexlibraryglobal{mul_sat}% |
| 10818 | +\begin{itemdecl} |
| 10819 | +template<class T> |
| 10820 | + constexpr T mul_sat(T x, T y) noexcept; |
| 10821 | +\end{itemdecl} |
| 10822 | + |
| 10823 | +\begin{itemdescr} |
| 10824 | +\pnum |
| 10825 | +\constraints |
| 10826 | +\tcode{T} is a signed or unsigned integer type\iref{basic.fundamental}. |
| 10827 | + |
| 10828 | +\pnum |
| 10829 | +\returns |
| 10830 | +If $\tcode{x} \times \tcode{y}$ is representable as a value of type \tcode{T}, $\tcode{x} \times \tcode{y}$; |
| 10831 | +otherwise, either the largest or smallest representable value of type \tcode{T}, |
| 10832 | +whichever is closer to the value of $\tcode{x} \times \tcode{y}$. |
| 10833 | +\end{itemdescr} |
| 10834 | + |
| 10835 | +\indexlibraryglobal{div_sat}% |
| 10836 | +\begin{itemdecl} |
| 10837 | +template<class T> |
| 10838 | + constexpr T div_sat(T x, T y) noexcept; |
| 10839 | +\end{itemdecl} |
| 10840 | + |
| 10841 | +\begin{itemdescr} |
| 10842 | +\pnum |
| 10843 | +\constraints |
| 10844 | +\tcode{T} is a signed or unsigned integer type\iref{basic.fundamental}. |
| 10845 | + |
| 10846 | +\pnum |
| 10847 | +\expects |
| 10848 | +\tcode{y != 0} is \tcode{true}. |
| 10849 | + |
| 10850 | +\pnum |
| 10851 | +\returns |
| 10852 | +If \tcode{T} is a signed integer type |
| 10853 | +and \tcode{x == numeric_limits<T>::min() \&\& y == -1} is \tcode{true}, |
| 10854 | +\tcode{numeric_limits<T>::max()}, otherwise, \tcode{x / y}. |
| 10855 | + |
| 10856 | +\pnum |
| 10857 | +\remarks |
| 10858 | +A function call expression |
| 10859 | +that violates the precondition in the \Fundescx{Preconditions} element |
| 10860 | +is not a core constant expression\iref{expr.const}. |
| 10861 | +\end{itemdescr} |
| 10862 | + |
| 10863 | +\rSec3[numeric.sat.cast]{Casting} |
| 10864 | + |
| 10865 | +\indexlibraryglobal{saturate_cast}% |
| 10866 | +\begin{itemdecl} |
| 10867 | +template<class R, class T> |
| 10868 | + constexpr R saturate_cast(T x) noexcept; |
| 10869 | +\end{itemdecl} |
| 10870 | + |
| 10871 | +\begin{itemdescr} |
| 10872 | +\pnum |
| 10873 | +\constraints |
| 10874 | +\tcode{R} and \tcode{T} are signed or unsigned integer types\iref{basic.fundamental}. |
| 10875 | + |
| 10876 | +\pnum |
| 10877 | +\returns |
| 10878 | +If \tcode{x} is representable as a value of type \tcode{R}, \tcode{x}; |
| 10879 | +otherwise, either the largest or smallest representable value of type \tcode{R}, |
| 10880 | +whichever is closer to the value of \tcode{x}. |
| 10881 | +\end{itemdescr} |
| 10882 | + |
10758 | 10883 | \rSec1[specialized.algorithms]{Specialized \tcode{<memory>} algorithms}
|
10759 | 10884 |
|
10760 | 10885 | \rSec2[specialized.algorithms.general]{General}
|
|
0 commit comments