cuda::sincos#
Defined in the <cuda/cmath> header.
namespace cuda {
template <class T>
struct sincos_result
{
T sin;
T cos;
};
template </*floating-point-type*/ T>
[[nodiscard]] __host__ __device__
sincos_result<T> sincos(T value) noexcept; // (1)
template <class Integral>
[[nodiscard]] __host__ __device__
sincos_result<double> sincos(Integral value) noexcept; // (2)
} // namespace cuda
Computes \(\sin value\) and \(\cos value\) at the same time using more efficient algorithms than if operations were computed separately.
Parameters
value: The input value.
Return value
cuda::sincos_resultobject with both values set toNaNif the input value is \(\pm\infty\) orNaNand to results of \(\sin value\) and \(\cos value\) otherwise. (1)if
Tis an integral type, the input value is treated asdouble. (2)
Constraints
Tis an arithmetic type.
Performance considerations
If available, the functionality is implemented by compiler builtins, otherwise fallbacks to
cuda::std::sin(value)andcuda::std::cos(value).
Example#
#include <cuda/cmath>
#include <cuda/std/cassert>
__global__ void sincos_kernel() {
auto [sin_pi, cos_pi] = cuda::sincos(0.f);
assert(sin_pi == 0.f);
assert(cos_pi == 1.f);
}
int main() {
sincos_kernel<<<1, 1>>>();
cudaDeviceSynchronize();
return 0;
}