以下の内容はhttps://yohhoy.hatenadiary.jp/entry/20231221/p1より取得しました。


飽和演算サポート @ C++26

C++2c(C++26)標準ライブラリに追加される飽和演算(saturation arithmetic)サポートについてメモ。

// C++2c <numeric>ヘッダ
namespace std {
  // T,U = 符号付き整数型 or 符号無し整数型
  template<class T>
    constexpr T add_sat(T x, T y) noexcept;
  template<class T>
    constexpr T sub_sat(T x, T y) noexcept;
  template<class T>
    constexpr T mul_sat(T x, T y) noexcept;
  template<class T>
    constexpr T div_sat(T x, T y) noexcept;
  template<class T, class U>
    constexpr T saturate_cast(U x) noexcept;
}
関数 効果
add_sat(x,y) 飽和加算(x + y)
sub_sat(x,y) 飽和減算(x - y)
mul_sat(x,y) 飽和乗算(x * y)
div_sat(x,y) 飽和除算(x / y)
saturate_cast<T>(x) 型キャスト飽和演算

メモ:信号処理分野では飽和演算が多用されるため、例えばOpenCVライブラリでは型キャスト飽和演算cv::saturate_cast<T>(x)が提供される。C++2c標準ライブラリ版はOpenCV版とは異なり、浮動小数点数からの型変換をサポートしない。*1

関連URL




以上の内容はhttps://yohhoy.hatenadiary.jp/entry/20231221/p1より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14