Files
2025-10-25 03:02:53 +03:00

325 lines
22 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[simd.math]
# 29 Numerics library [[numerics]](./#numerics)
## 29.10 Data-parallel types [[simd]](simd#math)
### 29.10.8 basic_vec non-member operations [[simd.nonmembers]](simd.nonmembers#simd.math)
#### 29.10.8.13 Mathematical functions [simd.math]
[🔗](#lib:ilogb,simd)
`template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<int, deduced-vec-t<V>> ilogb(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> ldexp(const V& x, const rebind_t<int, deduced-vec-t<V>>& exp);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> scalbn(const V& x, const rebind_t<int, deduced-vec-t<V>>& n);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V>
scalbln(const V& x, const rebind_t<long int, deduced-vec-t<V>>& n);
template<[signed_integral](concepts.arithmetic#concept:signed_integral "18.4.7Arithmetic concepts[concepts.arithmetic]") T, class Abi>
constexpr basic_vec<T, Abi> abs(const basic_vec<T, Abi>& j);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> abs(const V& j);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> fabs(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> ceil(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> floor(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
deduced-vec-t<V> nearbyint(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
deduced-vec-t<V> rint(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
rebind_t<long int, deduced-vec-t<V>> lrint(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
rebind_t<long long int, deduced-vec-t<V>> llrint(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> round(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<long int, deduced-vec-t<V>> lround(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<long long int, deduced-vec-t<V>> llround(const V& x);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> fmod(const V0& x, const V1& y);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> trunc(const V& x);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> remainder(const V0& x, const V1& y);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> copysign(const V0& x, const V1& y);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> nextafter(const V0& x, const V1& y);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> fdim(const V0& x, const V1& y);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> fmax(const V0& x, const V1& y);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> fmin(const V0& x, const V1& y);
template<class V0, class V1, class V2>
constexpr math-common-simd-t<V0, V1, V2> fma(const V0& x, const V1& y, const V2& z);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr rebind_t<int, deduced-vec-t<V>> fpclassify(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename deduced-vec-t<V>::mask_type isfinite(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename deduced-vec-t<V>::mask_type isinf(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename deduced-vec-t<V>::mask_type isnan(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename deduced-vec-t<V>::mask_type isnormal(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr typename deduced-vec-t<V>::mask_type signbit(const V& x);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type isgreater(const V0& x, const V1& y);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type
isgreaterequal(const V0& x, const V1& y);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type isless(const V0& x, const V1& y);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type islessequal(const V0& x, const V1& y);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type islessgreater(const V0& x, const V1& y);
template<class V0, class V1>
constexpr typename math-common-simd-t<V0, V1>::mask_type isunordered(const V0& x, const V1& y);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19451)
Let Ret denote the return type of the specialization of a function
template with the name *math-func*[.](#1.sentence-1)
Let *math-func-vec* denote:template<class... Args> Ret *math-func-vec*(Args... args) {return Ret([&](*simd-size-type* i) {*math-func*(*make-compatible-simd-t*<Ret, Args>(args)[i]...); });}
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19464)
*Returns*: A value ret of type Ret, that is element-wise equal to the
result of calling *math-func-vec* with the arguments of the above
functions[.](#2.sentence-1)
If in an invocation of a scalar overload of *math-func* for indexi in *math-func-vec* a domain, pole, or range error would
occur, the value of ret[i] is unspecified[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19473)
*Remarks*: It is unspecified whether errno ([[errno]](errno "19.4Error numbers")) is accessed[.](#3.sentence-1)
[🔗](#lib:acos,simd)
`template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> acos(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> asin(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> atan(const V& x);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> atan2(const V0& y, const V1& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> cos(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> sin(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> tan(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> acosh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> asinh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> atanh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> cosh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> sinh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> tanh(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> exp(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> exp2(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> expm1(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> log(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> log10(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> log1p(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> log2(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> logb(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> cbrt(const V& x);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> hypot(const V0& x, const V1& y);
template<class V0, class V1, class V2>
constexpr math-common-simd-t<V0, V1, V2> hypot(const V0& x, const V1& y, const V2& z);
template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> pow(const V0& x, const V1& y);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> sqrt(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> erf(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> erfc(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> lgamma(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> constexpr deduced-vec-t<V> tgamma(const V& x);
template<class V0, class V1, class V2>
constexpr math-common-simd-t<V0, V1, V2> lerp(const V0& a, const V1& b, const V2& t) noexcept;
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
deduced-vec-t<V> assoc_laguerre(const rebind_t<unsigned, deduced-vec-t<V>>& n, const
rebind_t<unsigned, deduced-vec-t<V>>& m,
const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
deduced-vec-t<V> assoc_legendre(const rebind_t<unsigned, deduced-vec-t<V>>& l, const
rebind_t<unsigned, deduced-vec-t<V>>& m,
const V& x);
template<class V0, class V1>
math-common-simd-t<V0, V1> beta(const V0& x, const V1& y);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> comp_ellint_1(const V& k);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> comp_ellint_2(const V& k);
template<class V0, class V1>
math-common-simd-t<V0, V1> comp_ellint_3(const V0& k, const V1& nu);
template<class V0, class V1>
math-common-simd-t<V0, V1> cyl_bessel_i(const V0& nu, const V1& x);
template<class V0, class V1>
math-common-simd-t<V0, V1> cyl_bessel_j(const V0& nu, const V1& x);
template<class V0, class V1>
math-common-simd-t<V0, V1> cyl_bessel_k(const V0& nu, const V1& x);
template<class V0, class V1>
math-common-simd-t<V0, V1> cyl_neumann(const V0& nu, const V1& x);
template<class V0, class V1>
math-common-simd-t<V0, V1> ellint_1(const V0& k, const V1& phi);
template<class V0, class V1>
math-common-simd-t<V0, V1> ellint_2(const V0& k, const V1& phi);
template<class V0, class V1, class V2>
math-common-simd-t<V0, V1, V2> ellint_3(const V0& k, const V1& nu, const V2& phi);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> expint(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> hermite(const rebind_t<unsigned,
deduced-vec-t<V>>& n, const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> laguerre(const rebind_t<unsigned,
deduced-vec-t<V>>& n, const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> legendre(const rebind_t<unsigned,
deduced-vec-t<V>>& l, const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> riemann_zeta(const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> sph_bessel(const rebind_t<unsigned,
deduced-vec-t<V>>& n, const V& x);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
deduced-vec-t<V> sph_legendre(const rebind_t<unsigned, deduced-vec-t<V>>& l,
const rebind_t<unsigned, deduced-vec-t<V>>& m,
const V& theta);
template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V> deduced-vec-t<V> sph_neumann(const rebind_t<unsigned,
deduced-vec-t<V>>& n, const V& x);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19614)
Let Ret denote the return type of the specialization of a function
template with the name *math-func*[.](#4.sentence-1)
Let *math-func-vec* denote:template<class... Args> Ret *math-func-vec*(Args... args) {return Ret([&](*simd-size-type* i) {*math-func*(*make-compatible-simd-t*<Ret, Args>(args)[i]...); });}
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19627)
*Returns*: A value ret of type Ret, that is element-wise approximately
equal to the result of calling *math-func-vec* with the arguments
of the above functions[.](#5.sentence-1)
If in an invocation of a scalar overload of *math-func* for indexi in *math-func-vec* a domain, pole, or range error would
occur, the value of ret[i] is unspecified[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19636)
*Remarks*: It is unspecified whether errno ([[errno]](errno "19.4Error numbers")) is accessed[.](#6.sentence-1)
[🔗](#lib:frexp,simd)
`template<[math-floating-point](simd.expos#concept:math-floating-point "29.10.2Exposition-only types, variables, and concepts[simd.expos]") V>
constexpr deduced-vec-t<V> frexp(const V& value, rebind_t<int, deduced-vec-t<V>>* exp);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19648)
Let Ret be *deduced-vec-t*<V>[.](#7.sentence-1)
Let *frexp-vec* denote:template<class V> pair<Ret, rebind_t<int, Ret>> *frexp-vec*(const V& x) {int r1[Ret::size()];
Ret r0([&](*simd-size-type* i) { frexp(*make-compatible-simd-t*<Ret, V>(x)[i], &r1[i]); }); return {r0, rebind_t<int, Ret>(r1)};}
Let ret be a value of type pair<Ret, rebind_t<int, Ret>> that is the same value as the result of calling*frexp-vec*(x)[.](#7.sentence-3)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19665)
*Effects*: Sets *exp to ret.second[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19669)
*Returns*: ret.first[.](#9.sentence-1)
[🔗](#lib:remquo,simd)
`template<class V0, class V1>
constexpr math-common-simd-t<V0, V1> remquo(const V0& x, const V1& y,
rebind_t<int, math-common-simd-t<V0, V1>>* quo);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19682)
Let Ret be *math-common-simd-t*<V0, V1>[.](#10.sentence-1)
Let *remquo-vec* denote:template<class V0, class V1> pair<Ret, rebind_t<int, Ret>> *remquo-vec*(const V0& x, const V1& y) {int r1[Ret::size()];
Ret r0([&](*simd-size-type* i) { remquo(*make-compatible-simd-t*<Ret, V0>(x)[i], *make-compatible-simd-t*<Ret, V1>(y)[i], &r1[i]); }); return {r0, rebind_t<int, Ret>(r1)};}
Let ret be a value of type pair<Ret, rebind_t<int, Ret>> that is the same value as the result of calling*remquo-vec*(x, y)[.](#10.sentence-3)
If in an invocation of a scalar overload of remquo for index i in *remquo-vec* a domain, pole, or range error would occur, the
value of ret[i] is unspecified[.](#10.sentence-4)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19703)
*Effects*: Sets *quo to ret.second[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19707)
*Returns*: ret.first[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19711)
*Remarks*: It is unspecified whether errno ([[errno]](errno "19.4Error numbers")) is accessed[.](#13.sentence-1)
[🔗](#lib:modf,simd)
`template<class T, class Abi>
constexpr basic_vec<T, Abi> modf(const type_identity_t<basic_vec<T, Abi>>& value,
basic_vec<T, Abi>* iptr);
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19724)
Let V be basic_vec<T, Abi>[.](#14.sentence-1)
Let *modf-vec* denote:pair<V, V> *modf-vec*(const V& x) { T r1[Ret::size()];
V r0([&](*simd-size-type* i) { modf(V(x)[i], &r1[i]); }); return {r0, V(r1)};}
Let ret be a value of type pair<V, V> that is the same value as
the result of calling *modf-vec*(value)[.](#14.sentence-3)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19739)
*Effects*: Sets *iptr to ret.second[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L19743)
*Returns*: ret.first[.](#16.sentence-1)