Skip to content

Latest commit

 

History

History
89 lines (66 loc) · 3.45 KB

File metadata and controls

89 lines (66 loc) · 3.45 KB

fmax

  • simd[meta header]
  • std::simd[meta namespace]
  • function template[meta id-type]
  • cpp26[meta cpp]
namespace std::simd {
  template<math-floating-point V>
  constexpr deduced-vec-t<V> fmax(const V& x, const V& y);                     // (1) C++26
  template<math-floating-point V>
  constexpr deduced-vec-t<V> fmax(const deduced-vec-t<V>& x, const V& y);  // (2) C++26
  template<math-floating-point V>
  constexpr deduced-vec-t<V> fmax(const V& x, const deduced-vec-t<V>& y);  // (3) C++26
}
  • deduced-vec-t[link /reference/simd/deduced-vec-t.md]
  • math-floating-point[link /reference/simd/math-floating-point.md]

概要

basic_vecの各要素について、大きいほうの値を求める。一方がNaNの場合はもう一方の値を返す。

制約math-floating-pointは、Vが浮動小数点要素のbasic_vec、またはそこからbasic_vecを導出可能なスカラー浮動小数点型であることを表す説明専用のコンセプトである。deduced-vec-t<V>は、Vに対応するbasic_vec型(Vがスカラー型のときはそれを要素型とするbasic_vec)を表す。

  • (1) : 両引数が同じ型Vの場合。
  • (2), (3) : 一方の引数をbasic_vec、他方をスカラー値として、スカラー側を全要素に対して適用する場合。

戻り値

各要素iについて、xyの対応する要素に<cmath>fmaxを適用した結果で初期化されたdeduced-vec-t<V>型のオブジェクトを返す。

ある要素iについて定義域エラー・極エラー・値域エラーが発生する場合、その要素の値は未規定である。

備考

errnoにアクセスするか否かは未規定である。

#include <simd>
#include <print>

namespace simd = std::simd;

int main()
{
  simd::vec<float, 4> x{[](int i) { constexpr float a[] = {1, 5, 3, 8}; return a[i]; }};
  simd::vec<float, 4> y{[](int i) { constexpr float a[] = {4, 2, 6, 7}; return a[i]; }};

  // 各要素の最大値
  simd::vec<float, 4> r = simd::fmax(x, y);

  for (int i = 0; i < r.size(); ++i)
    std::print("{} ", r[i]);
  std::println("");
}
  • simd::fmax[color ff0000]
  • simd::vec[link basic_vec.md]

出力

4 5 6 8 

バージョン

言語

  • C++26

処理系

関連項目

参照