[INFRA] Import NVIDIA/CCCL upstream as optimization reference library
CCCL (CUDA C++ Core Libraries) provides: - CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk) - Thrust: high-level parallel algorithms (transform_reduce, sort, scan) - libcudacxx: CUDA C++ standard library (atomics, barriers, memory) - cudax: experimental features (memory resources, allocators) - Tuning policies: per-SM hardware-specific algorithm parameters Competition optimization vectors mapped to CCCL: - Output TPS (83% weight): warp_reduce, block_reduce, device_topk - Input TPS (14% weight): device_scan, block_load, prefetch - Cache TPS (3% weight): prefix caching strategy patterns - Memory (0.9 util): pooled/cached/buddy allocators Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only) License: Apache-2.0
This commit is contained in:
163
cccl_upstream/libcudacxx/include/cuda/std/__cmath/abs.h
Normal file
163
cccl_upstream/libcudacxx/include/cuda/std/__cmath/abs.h
Normal file
@@ -0,0 +1,163 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ABS_H
|
||||
#define _CUDA_STD___CMATH_ABS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fabs) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FABSF(...) __builtin_fabsf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FABS(...) __builtin_fabs(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FABSL(...) __builtin_fabsl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_fabs)
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
# if _CCCL_CHECK_BUILTIN(builtin_fabsf128) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FABSF128(...) __builtin_fabsf128(__VA_ARGS__)
|
||||
# endif // _CCCL_CHECK_BUILTIN(builtin_fabsf128) || _CCCL_COMPILER(GCC)
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
// nvcc doesn't implement __builtin_fabsf128 on device
|
||||
#if _CCCL_CUDA_COMPILER(NVCC) && _CCCL_DEVICE_COMPILATION()
|
||||
# undef _CCCL_BUILTIN_FABSF128
|
||||
#endif // _CCCL_CUDA_COMPILER(NVCC) && _CCCL_DEVICE_COMPILATION()
|
||||
|
||||
#if _CCCL_TILE_COMPILATION()
|
||||
# undef _CCCL_BUILTIN_FABSF
|
||||
# undef _CCCL_BUILTIN_FABS
|
||||
# undef _CCCL_BUILTIN_FABSL
|
||||
#endif // _CCCL_TILE_COMPILATION()
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// fabs
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr auto fabs(_Tp __x) noexcept
|
||||
{
|
||||
if constexpr (!numeric_limits<_Tp>::is_signed)
|
||||
{
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return static_cast<double>(__x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
}
|
||||
else if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return __x < 0 ? -static_cast<double>(__x) : static_cast<double>(__x);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _CCCL_BUILTIN_FABSF
|
||||
if constexpr (is_same_v<_Tp, float>)
|
||||
{
|
||||
return _CCCL_BUILTIN_FABSF(__x);
|
||||
}
|
||||
else if constexpr (is_same_v<_Tp, double>)
|
||||
{
|
||||
return _CCCL_BUILTIN_FABS(__x);
|
||||
}
|
||||
# if _CCCL_HAS_LONG_DOUBLE()
|
||||
else if constexpr (is_same_v<_Tp, long double>)
|
||||
{
|
||||
return _CCCL_BUILTIN_FABSL(__x);
|
||||
}
|
||||
# endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
#endif // _CCCL_BUILTIN_FABSF
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
if constexpr (is_same_v<_Tp, __half>)
|
||||
{
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::__habs(__x);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
if constexpr (is_same_v<_Tp, __nv_bfloat16>)
|
||||
{
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::__habs(__x);
|
||||
}
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
if constexpr (is_same_v<_Tp, __float128>)
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FABSF128)
|
||||
// nvcc doesn't support _CCCL_BUILTIN_FABSF128 in constexpr context
|
||||
# if _CCCL_CUDA_COMPILER(NVCC)
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
# endif // _CCCL_CUDA_COMPILER(NVCC)
|
||||
{
|
||||
return static_cast<__float128>(_CCCL_BUILTIN_FABSF128(__x));
|
||||
}
|
||||
# else // ^^^ _CCCL_BUILTIN_FABSF128 ^^^ / vvv !_CCCL_BUILTIN_FABSF128 vvv
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_IS_DEVICE, (return ::__nv_fp128_fabs(__x);))
|
||||
}
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FABSF128 ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
const auto __val = ::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<_Tp>;
|
||||
return ::cuda::std::__fp_from_storage<_Tp>(static_cast<__fp_storage_of_t<_Tp>>(__val));
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float fabsf(float __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fabs(__x);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double fabsl(long double __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fabs(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
// abs
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_fp_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr auto abs(_Tp __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fabs(__x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ABS_H
|
||||
119
cccl_upstream/libcudacxx/include/cuda/std/__cmath/copysign.h
Normal file
119
cccl_upstream/libcudacxx/include/cuda/std/__cmath/copysign.h
Normal file
@@ -0,0 +1,119 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_COPYSIGN_H
|
||||
#define _CUDA_STD___CMATH_COPYSIGN_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
# if _CCCL_CHECK_BUILTIN(builtin_copysignf128) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_COPYSIGNF128(...) __builtin_copysignf128(__VA_ARGS__)
|
||||
# endif // _CCCL_CHECK_BUILTIN(builtin_copysignf128) || _CCCL_COMPILER(GCC)
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
// nvcc doesn't implement __builtin_copysignf128 on device
|
||||
#if _CCCL_CUDA_COMPILER(NVCC) && _CCCL_DEVICE_COMPILATION()
|
||||
# undef _CCCL_BUILTIN_COPYSIGNF128
|
||||
#endif // _CCCL_CUDA_COMPILER(NVCC) && _CCCL_DEVICE_COMPILATION()
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr auto copysign(_Tp __x, [[maybe_unused]] _Tp __y) noexcept
|
||||
{
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
if constexpr (!numeric_limits<_Tp>::is_signed)
|
||||
{
|
||||
return static_cast<double>(__x);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto __x_dbl = static_cast<double>(__x);
|
||||
if (__y < 0)
|
||||
{
|
||||
return (__x < 0) ? __x_dbl : -__x_dbl;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (__x < 0) ? -__x_dbl : __x_dbl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // ^^^ integral ^^^ / vvv floating_point vvv
|
||||
{
|
||||
if constexpr (!numeric_limits<_Tp>::is_signed)
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
if constexpr (is_same_v<_Tp, __float128>)
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_COPYSIGNF128)
|
||||
// nvcc doesn't support _CCCL_BUILTIN_COPYSIGNF128 in constexpr context
|
||||
# if _CCCL_CUDA_COMPILER(NVCC)
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
# endif // _CCCL_CUDA_COMPILER(NVCC)
|
||||
{
|
||||
return static_cast<__float128>(_CCCL_BUILTIN_COPYSIGNF128(__x, __y));
|
||||
}
|
||||
# else // ^^^ _CCCL_BUILTIN_COPYSIGNF128 ^^^ / vvv !_CCCL_BUILTIN_COPYSIGNF128 vvv
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_IS_DEVICE, (return ::__nv_fp128_copysign(__x, __y);))
|
||||
}
|
||||
# endif // ^^^ !_CCCL_BUILTIN_COPYSIGNF128 ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
const auto __val = (::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<_Tp>)
|
||||
| (::cuda::std::__fp_get_storage(__y) & __fp_sign_mask_of_v<_Tp>);
|
||||
return ::cuda::std::__fp_from_storage<_Tp>(static_cast<__fp_storage_of_t<_Tp>>(__val));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float copysignf(float __x, float __y) noexcept
|
||||
{
|
||||
return ::cuda::std::copysign(__x, __y);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double copysignl(long double __x, long double __y) noexcept
|
||||
{
|
||||
return ::cuda::std::copysign(__x, __y);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_COPYSIGN_H
|
||||
@@ -0,0 +1,201 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ERROR_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_ERROR_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// erf
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_erf) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ERFF(...) __builtin_erff(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ERF(...) __builtin_erf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ERFL(...) __builtin_erfl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_erf)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG) // Unresolved extern function 'erf'
|
||||
# undef _CCCL_BUILTIN_ERFF
|
||||
# undef _CCCL_BUILTIN_ERF
|
||||
# undef _CCCL_BUILTIN_ERFL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float erf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERFF)
|
||||
return _CCCL_BUILTIN_ERFF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERFF ^^^ / vvv !_CCCL_BUILTIN_ERFF vvv
|
||||
return ::erff(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERFF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float erff(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERFF)
|
||||
return _CCCL_BUILTIN_ERFF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERFF ^^^ / vvv !_CCCL_BUILTIN_ERFF vvv
|
||||
return ::erff(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERFF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double erf(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERF)
|
||||
return _CCCL_BUILTIN_ERF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERF ^^^ / vvv !_CCCL_BUILTIN_ERF vvv
|
||||
return ::erf(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERF ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double erf(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ERFL)
|
||||
return _CCCL_BUILTIN_ERFL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ERFL ^^^ / vvv !_CCCL_BUILTIN_ERFL vvv
|
||||
return ::erfl(__x);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ERFL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double erfl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ERFL)
|
||||
return _CCCL_BUILTIN_ERFL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ERFL ^^^ / vvv !_CCCL_BUILTIN_ERFL vvv
|
||||
return ::erfl(__x);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ERFL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half erf(__half __x) noexcept
|
||||
{
|
||||
return ::__float2half(::cuda::std::erf(::__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 erf(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::__float2bfloat16(::cuda::std::erf(::__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double erf(_Tp __x) noexcept
|
||||
{
|
||||
return ::cuda::std::erf(static_cast<double>(__x));
|
||||
}
|
||||
|
||||
// erfc
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_ercf) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ERFCF(...) __builtin_erfcf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ERFC(...) __builtin_erfc(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ERFCL(...) __builtin_erfcl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_ercf)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG) // Unresolved extern function 'erfc'
|
||||
# undef _CCCL_BUILTIN_ERFCF
|
||||
# undef _CCCL_BUILTIN_ERFC
|
||||
# undef _CCCL_BUILTIN_ERFCL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float erfc(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERFCF)
|
||||
return _CCCL_BUILTIN_ERFCF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERFCF ^^^ / vvv !_CCCL_BUILTIN_ERFCF vvv
|
||||
return ::erfcf(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERFCF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float erfcf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERFCF)
|
||||
return _CCCL_BUILTIN_ERFCF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERFCF ^^^ / vvv !_CCCL_BUILTIN_ERFCF vvv
|
||||
return ::erfcf(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERFCF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double erfc(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ERFC)
|
||||
return _CCCL_BUILTIN_ERFC(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ERFC ^^^ / vvv !_CCCL_BUILTIN_ERFC vvv
|
||||
return ::erfc(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ERFC ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double erfc(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ERFCL)
|
||||
return _CCCL_BUILTIN_ERFCL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ERFCL ^^^ / vvv !_CCCL_BUILTIN_ERFCL vvv
|
||||
return ::erfcl(__x);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ERFCL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double erfcl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ERFCL)
|
||||
return _CCCL_BUILTIN_ERFCL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ERFCL ^^^ / vvv !_CCCL_BUILTIN_ERFCL vvv
|
||||
return ::erfcl(__x);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ERFCL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half erfc(__half __x) noexcept
|
||||
{
|
||||
return ::__float2half(::cuda::std::erfc(::__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 erfc(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::__float2bfloat16(::cuda::std::erfc(::__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double erfc(_Tp __x) noexcept
|
||||
{
|
||||
return ::cuda::std::erfc(static_cast<double>(__x));
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ERROR_FUNCTIONS_H
|
||||
@@ -0,0 +1,784 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___MATH_EXPONENTIAL_FUNCTIONS_H
|
||||
#define _CUDA_STD___MATH_EXPONENTIAL_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/abs.h>
|
||||
#include <cuda/std/__cmath/isinf.h>
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
#include <cuda/std/cstdint>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// exp
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_exp) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_EXPF(...) __builtin_expf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXP(...) __builtin_exp(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXPL(...) __builtin_expl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_exp)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "expf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_EXPF
|
||||
# undef _CCCL_BUILTIN_EXP
|
||||
# undef _CCCL_BUILTIN_EXPL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float exp(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXPF)
|
||||
return _CCCL_BUILTIN_EXPF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXPF ^^^ // vvv !_CCCL_BUILTIN_EXPF vvv
|
||||
return ::expf(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float expf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXPF)
|
||||
return _CCCL_BUILTIN_EXPF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXPF ^^^ // vvv !_CCCL_BUILTIN_EXPF vvv
|
||||
return ::expf(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double exp(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXP)
|
||||
return _CCCL_BUILTIN_EXP(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXP ^^^ // vvv !_CCCL_BUILTIN_EXP vvv
|
||||
return ::exp(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXP
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double exp(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXPL)
|
||||
return _CCCL_BUILTIN_EXPL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXPL ^^^ // vvv !_CCCL_BUILTIN_EXPL vvv
|
||||
return ::expl(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXPL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double expl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXPL)
|
||||
return _CCCL_BUILTIN_EXPL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXPL ^^^ // vvv !_CCCL_BUILTIN_EXPL vvv
|
||||
return ::expl(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXPL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half exp(__half __x) noexcept
|
||||
{
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_53, (return ::hexp(__x);), ({
|
||||
float __xf = __half2float(__x);
|
||||
__xf = ::expf(__xf);
|
||||
__half_raw __ret_repr = ::__float2half_rn(__xf);
|
||||
|
||||
uint16_t __repr = ::cuda::std::__fp_get_storage(__x);
|
||||
switch (__repr)
|
||||
{
|
||||
case 8057:
|
||||
case 9679:
|
||||
__ret_repr.x -= 1;
|
||||
break;
|
||||
|
||||
default:;
|
||||
}
|
||||
|
||||
return __ret_repr;
|
||||
}))
|
||||
}
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 exp(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hexp(__x);), (return __float2bfloat16(::cuda::std::expf(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double exp(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::exp((double) __x);
|
||||
}
|
||||
|
||||
// frexp
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_frexp) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FREXPF(...) __builtin_frexpf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FREXP(...) __builtin_frexp(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FREXPL(...) __builtin_frexpl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_frexp)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "frexp"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_FREXPF
|
||||
# undef _CCCL_BUILTIN_FREXP
|
||||
# undef _CCCL_BUILTIN_FREXPL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float frexp(float __x, int* __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FREXPF)
|
||||
return _CCCL_BUILTIN_FREXPF(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_FREXPF ^^^ // vvv !_CCCL_BUILTIN_FREXPF vvv
|
||||
return ::frexpf(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_FREXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float frexpf(float __x, int* __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FREXPF)
|
||||
return _CCCL_BUILTIN_FREXPF(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_FREXPF ^^^ // vvv !_CCCL_BUILTIN_FREXPF vvv
|
||||
return ::frexpf(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_FREXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double frexp(double __x, int* __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FREXP)
|
||||
return _CCCL_BUILTIN_FREXP(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_FREXP ^^^ // vvv !_CCCL_BUILTIN_FREXP vvv
|
||||
return ::frexp(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_FREXP
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double frexp(long double __x, int* __e) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FREXPL)
|
||||
return _CCCL_BUILTIN_FREXPL(__x, __e);
|
||||
# else // ^^^ _CCCL_BUILTIN_FREXPL ^^^ // vvv !_CCCL_BUILTIN_FREXPL vvv
|
||||
return ::frexpl(__x, __e);
|
||||
# endif // !_CCCL_BUILTIN_FREXPL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double frexpl(long double __x, int* __e) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FREXPL)
|
||||
return _CCCL_BUILTIN_FREXPL(__x, __e);
|
||||
# else // ^^^ _CCCL_BUILTIN_FREXPL ^^^ // vvv !_CCCL_BUILTIN_FREXPL vvv
|
||||
return ::frexpl(__x, __e);
|
||||
# endif // !_CCCL_BUILTIN_FREXPL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half frexp(__half __x, int* __e) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::frexpf(__half2float(__x), __e));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 frexp(__nv_bfloat16 __x, int* __e) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::frexpf(__bfloat162float(__x), __e));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double frexp(_Integer __x, int* __e) noexcept
|
||||
{
|
||||
return ::cuda::std::frexp((double) __x, __e);
|
||||
}
|
||||
|
||||
// ldexp
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_ldexp) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LDEXPF(...) __builtin_ldexpf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LDEXP(...) __builtin_ldexp(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LDEXPL(...) __builtin_ldexpl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_ldexp)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "ldexp"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LDEXPF
|
||||
# undef _CCCL_BUILTIN_LDEXP
|
||||
# undef _CCCL_BUILTIN_LDEXPL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float ldexp(float __x, int __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LDEXPF)
|
||||
return _CCCL_BUILTIN_LDEXPF(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_LDEXPF ^^^ // vvv !_CCCL_BUILTIN_LDEXPF vvv
|
||||
return ::ldexpf(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_LDEXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float ldexpf(float __x, int __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LDEXPF)
|
||||
return _CCCL_BUILTIN_LDEXPF(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_LDEXPF ^^^ // vvv !_CCCL_BUILTIN_LDEXPF vvv
|
||||
return ::ldexpf(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_LDEXPF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double ldexp(double __x, int __e) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LDEXP)
|
||||
return _CCCL_BUILTIN_LDEXP(__x, __e);
|
||||
#else // ^^^ _CCCL_BUILTIN_LDEXP ^^^ // vvv !_CCCL_BUILTIN_LDEXP vvv
|
||||
return ::ldexp(__x, __e);
|
||||
#endif // !_CCCL_BUILTIN_LDEXP
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double ldexp(long double __x, int __e) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LDEXPL)
|
||||
return _CCCL_BUILTIN_LDEXPL(__x, __e);
|
||||
# else // ^^^ _CCCL_BUILTIN_LDEXPL ^^^ // vvv !_CCCL_BUILTIN_LDEXPL vvv
|
||||
return ::ldexpl(__x, __e);
|
||||
# endif // !_CCCL_BUILTIN_LDEXPL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double ldexpl(long double __x, int __e) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LDEXPL)
|
||||
return _CCCL_BUILTIN_LDEXPL(__x, __e);
|
||||
# else // ^^^ _CCCL_BUILTIN_LDEXPL ^^^ // vvv !_CCCL_BUILTIN_LDEXPL vvv
|
||||
return ::ldexpl(__x, __e);
|
||||
# endif // !_CCCL_BUILTIN_LDEXPL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half ldexp(__half __x, int __e) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::ldexpf(__half2float(__x), __e));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 ldexp(__nv_bfloat16 __x, int __e) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::ldexpf(__bfloat162float(__x), __e));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double ldexp(_Integer __x, int __e) noexcept
|
||||
{
|
||||
return ::cuda::std::ldexp((double) __x, __e);
|
||||
}
|
||||
|
||||
// exp2
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_exp2) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_EXP2F(...) __builtin_exp2f(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXP2(...) __builtin_exp2(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXP2L(...) __builtin_exp2l(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_exp2)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "exp2"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_EXP2F
|
||||
# undef _CCCL_BUILTIN_EXP2
|
||||
# undef _CCCL_BUILTIN_EXP2L
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float exp2(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXP2F)
|
||||
return _CCCL_BUILTIN_EXP2F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXP2F ^^^ // vvv !_CCCL_BUILTIN_EXP2F vvv
|
||||
return ::exp2f(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXP2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float exp2f(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXP2F)
|
||||
return _CCCL_BUILTIN_EXP2F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXP2F ^^^ // vvv !_CCCL_BUILTIN_EXP2F vvv
|
||||
return ::exp2f(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXP2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double exp2(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXP2)
|
||||
return _CCCL_BUILTIN_EXP2(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXP2 ^^^ // vvv !_CCCL_BUILTIN_EXP2 vvv
|
||||
return ::exp2(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXP2
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double exp2(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXP2L)
|
||||
return _CCCL_BUILTIN_EXP2L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXP2L ^^^ // vvv !_CCCL_BUILTIN_EXP2L vvv
|
||||
return ::exp2l(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXP2L
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double exp2l(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXP2L)
|
||||
return _CCCL_BUILTIN_EXP2L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXP2L ^^^ // vvv !_CCCL_BUILTIN_EXP2L vvv
|
||||
return ::exp2l(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXP2L
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half exp2(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::hexp2(__x);), (return __float2half(::cuda::std::exp2f(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 exp2(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hexp2(__x);), (return __float2bfloat16(::cuda::std::exp2f(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double exp2(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::exp2((double) __x);
|
||||
}
|
||||
|
||||
// expm1
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_expm1) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_EXPM1F(...) __builtin_expm1f(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXPM1(...) __builtin_expm1(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_EXPM1L(...) __builtin_expm1l(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_expm1)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "expm1"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_EXPM1F
|
||||
# undef _CCCL_BUILTIN_EXPM1
|
||||
# undef _CCCL_BUILTIN_EXPM1L
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float expm1(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXPM1F)
|
||||
return _CCCL_BUILTIN_EXPM1F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXPM1F ^^^ // vvv !_CCCL_BUILTIN_EXPM1F vvv
|
||||
return ::expm1f(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXPM1F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float expm1f(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXPM1F)
|
||||
return _CCCL_BUILTIN_EXPM1F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXPM1F ^^^ // vvv !_CCCL_BUILTIN_EXPM1F vvv
|
||||
return ::expm1f(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXPM1F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double expm1(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_EXPM1)
|
||||
return _CCCL_BUILTIN_EXPM1(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_EXPM1 ^^^ // vvv !_CCCL_BUILTIN_EXPM1 vvv
|
||||
return ::expm1(__x);
|
||||
#endif // !_CCCL_BUILTIN_EXPM1
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double expm1(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXPM1L)
|
||||
return _CCCL_BUILTIN_EXPM1L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXPM1L ^^^ // vvv !_CCCL_BUILTIN_EXPM1L vvv
|
||||
return ::expm1l(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXPM1L
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double expm1l(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_EXPM1L)
|
||||
return _CCCL_BUILTIN_EXPM1L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_EXPM1L ^^^ // vvv !_CCCL_BUILTIN_EXPM1L vvv
|
||||
return ::expm1l(__x);
|
||||
# endif // !_CCCL_BUILTIN_EXPM1L
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half expm1(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::expm1f(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 expm1(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::expm1f(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double expm1(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::expm1((double) __x);
|
||||
}
|
||||
|
||||
// scalbln
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_scalbln) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_SCALBLNF(...) __builtin_scalblnf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SCALBLN(...) __builtin_scalbln(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SCALBLNL(...) __builtin_scalblnl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_scalbln)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "scalblnf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_SCALBLNF
|
||||
# undef _CCCL_BUILTIN_SCALBLN
|
||||
# undef _CCCL_BUILTIN_SCALBLNL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float scalbln(float __x, long __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBLNF)
|
||||
return _CCCL_BUILTIN_SCALBLNF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBLNF ^^^ // vvv !_CCCL_BUILTIN_SCALBLNF vvv
|
||||
return ::scalblnf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBLNF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float scalblnf(float __x, long __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBLNF)
|
||||
return _CCCL_BUILTIN_SCALBLNF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBLNF ^^^ // vvv !_CCCL_BUILTIN_SCALBLNF vvv
|
||||
return ::scalblnf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBLNF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double scalbln(double __x, long __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBLN)
|
||||
return _CCCL_BUILTIN_SCALBLN(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBLN ^^^ // vvv !_CCCL_BUILTIN_SCALBLN vvv
|
||||
return ::scalbln(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBLN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double scalbln(long double __x, long __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SCALBLNL)
|
||||
return _CCCL_BUILTIN_SCALBLNL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_SCALBLNL ^^^ // vvv !_CCCL_BUILTIN_SCALBLNL vvv
|
||||
return ::scalblnl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_SCALBLNL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double scalblnl(long double __x, long __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SCALBLNL)
|
||||
return _CCCL_BUILTIN_SCALBLNL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_SCALBLNL ^^^ // vvv !_CCCL_BUILTIN_SCALBLNL vvv
|
||||
return ::scalblnl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_SCALBLNL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half scalbln(__half __x, long __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::scalblnf(__half2float(__x), __y));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 scalbln(__nv_bfloat16 __x, long __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::scalblnf(__bfloat162float(__x), __y));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double scalbln(_Integer __x, long __y) noexcept
|
||||
{
|
||||
return ::cuda::std::scalbln((double) __x, __y);
|
||||
}
|
||||
|
||||
// scalbn
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_scalbn) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_SCALBNF(...) __builtin_scalbnf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SCALBN(...) __builtin_scalbn(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SCALBNL(...) __builtin_scalbnl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_scalbn)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "scalbnf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_SCALBNF
|
||||
# undef _CCCL_BUILTIN_SCALBN
|
||||
# undef _CCCL_BUILTIN_SCALBNL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float scalbn(float __x, int __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBNF)
|
||||
return _CCCL_BUILTIN_SCALBNF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBNF ^^^ // vvv !_CCCL_BUILTIN_SCALBNF vvv
|
||||
return ::scalbnf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBNF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float scalbnf(float __x, int __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBNF)
|
||||
return _CCCL_BUILTIN_SCALBNF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBNF ^^^ // vvv !_CCCL_BUILTIN_SCALBNF vvv
|
||||
return ::scalbnf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBNF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double scalbn(double __x, int __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SCALBN)
|
||||
return _CCCL_BUILTIN_SCALBN(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_SCALBN ^^^ // vvv !_CCCL_BUILTIN_SCALBN vvv
|
||||
return ::scalbn(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_SCALBN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double scalbn(long double __x, int __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SCALBNL)
|
||||
return _CCCL_BUILTIN_SCALBNL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_SCALBNL ^^^ // vvv !_CCCL_BUILTIN_SCALBNL vvv
|
||||
return ::scalbnl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_SCALBNL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double scalbnl(long double __x, int __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SCALBNL)
|
||||
return _CCCL_BUILTIN_SCALBNL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_SCALBNL ^^^ // vvv !_CCCL_BUILTIN_SCALBNL vvv
|
||||
return ::scalbnl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_SCALBNL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half scalbn(__half __x, int __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::scalbnf(__half2float(__x), __y));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 scalbn(__nv_bfloat16 __x, int __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::scalbnf(__bfloat162float(__x), __y));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double scalbn(_Integer __x, int __y) noexcept
|
||||
{
|
||||
return ::cuda::std::scalbn((double) __x, __y);
|
||||
}
|
||||
|
||||
template <class _Tp>
|
||||
_CCCL_API inline constexpr _Tp __constexpr_scalbn(_Tp __x, int __exp)
|
||||
{
|
||||
#if !_CCCL_TILE_COMPILATION()
|
||||
_CCCL_IF_CONSTEVAL
|
||||
#endif // !_CCCL_TILE_COMPILATION()
|
||||
{
|
||||
if (__x == _Tp(0))
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
|
||||
if (::cuda::std::isinf(__x))
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
|
||||
if (_Tp(__exp) == _Tp(0))
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
|
||||
if (::cuda::std::isnan(__x))
|
||||
{
|
||||
return numeric_limits<_Tp>::quiet_NaN();
|
||||
}
|
||||
|
||||
_Tp __mult(1);
|
||||
if (__exp > 0)
|
||||
{
|
||||
__mult = numeric_limits<_Tp>::radix;
|
||||
--__exp;
|
||||
}
|
||||
else
|
||||
{
|
||||
++__exp;
|
||||
__exp = -__exp;
|
||||
__mult /= numeric_limits<_Tp>::radix;
|
||||
}
|
||||
|
||||
while (__exp > 0)
|
||||
{
|
||||
if (!(__exp & 1))
|
||||
{
|
||||
__mult *= __mult;
|
||||
__exp >>= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
__x *= __mult;
|
||||
--__exp;
|
||||
}
|
||||
}
|
||||
return __x;
|
||||
}
|
||||
#if !_CCCL_TILE_COMPILATION()
|
||||
return ::cuda::std::scalbn(__x, __exp);
|
||||
#endif // !_CCCL_TILE_COMPILATION()
|
||||
}
|
||||
|
||||
// pow
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_pow) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_POWF(...) __builtin_powf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_POW(...) __builtin_pow(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_POWL(...) __builtin_powl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_pow)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "pow"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_POWF
|
||||
# undef _CCCL_BUILTIN_POW
|
||||
# undef _CCCL_BUILTIN_POWL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float pow(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_POWF)
|
||||
return _CCCL_BUILTIN_POWF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_POWF ^^^ // vvv !_CCCL_BUILTIN_POWF vvv
|
||||
return ::powf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_POWF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float powf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_POWF)
|
||||
return _CCCL_BUILTIN_POWF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_POWF ^^^ // vvv !_CCCL_BUILTIN_POWF vvv
|
||||
return ::powf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_POWF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double pow(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_POW)
|
||||
return _CCCL_BUILTIN_POW(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_POW ^^^ // vvv !_CCCL_BUILTIN_POW vvv
|
||||
return ::pow(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_POW
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double pow(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_POWL)
|
||||
return _CCCL_BUILTIN_POWL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_POWL ^^^ // vvv !_CCCL_BUILTIN_POWL vvv
|
||||
return ::powl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_POWL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double powl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_POWL)
|
||||
return _CCCL_BUILTIN_POWL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_POWL ^^^ // vvv !_CCCL_BUILTIN_POWL vvv
|
||||
return ::powl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_POWL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half pow(__half __x, __half __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::powf(__half2float(__x), __half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 pow(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::powf(__bfloat162float(__x), __bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __promote_t<_A1, _A2> pow(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::pow((__result_type) __x, (__result_type) __y);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___MATH_EXPONENTIAL_FUNCTIONS_H
|
||||
119
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fdim.h
Normal file
119
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fdim.h
Normal file
@@ -0,0 +1,119 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_FDIM_H
|
||||
#define _CUDA_STD___CMATH_FDIM_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// fdim
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fdim) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FDIMF(...) __builtin_fdimf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FDIM(...) __builtin_fdim(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FDIML(...) __builtin_fdiml(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_fdim)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG) // Unresolved extern function 'fdim'
|
||||
# undef _CCCL_BUILTIN_FDIMF
|
||||
# undef _CCCL_BUILTIN_FDIM
|
||||
# undef _CCCL_BUILTIN_FDIML
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float fdim(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FDIMF)
|
||||
return _CCCL_BUILTIN_FDIMF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FDIMF ^^^ / vvv !_CCCL_BUILTIN_FDIMF vvv
|
||||
return ::fdimf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FDIMF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float fdimf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FDIMF)
|
||||
return _CCCL_BUILTIN_FDIMF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FDIMF ^^^ / vvv !_CCCL_BUILTIN_FDIMF vvv
|
||||
return ::fdimf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FDIMF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double fdim(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FDIM)
|
||||
return _CCCL_BUILTIN_FDIM(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FDIM ^^^ / vvv !_CCCL_BUILTIN_FDIM vvv
|
||||
return ::fdim(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FDIM ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double fdim(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FDIML)
|
||||
return _CCCL_BUILTIN_FDIML(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_FDIML ^^^ / vvv !_CCCL_BUILTIN_FDIML vvv
|
||||
return ::fdiml(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FDIML ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double fdiml(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FDIML)
|
||||
return _CCCL_BUILTIN_FDIML(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_FDIML ^^^ / vvv !_CCCL_BUILTIN_FDIML vvv
|
||||
return ::fdiml(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FDIML ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half fdim(__half __x, __half __y) noexcept
|
||||
{
|
||||
return ::__float2half(::cuda::std::fdim(::__half2float(__x), ::__half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 fdim(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return ::__float2bfloat16(::cuda::std::fdim(::__bfloat162float(__x), ::__bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API constexpr double fdim(_Tp __x, _Tp __y) noexcept
|
||||
{
|
||||
return ::cuda::std::fdim(static_cast<double>(__x), static_cast<double>(__y));
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_FDIM_H
|
||||
127
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fma.h
Normal file
127
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fma.h
Normal file
@@ -0,0 +1,127 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_FMA_H
|
||||
#define _CUDA_STD___CMATH_FMA_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// fma
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fma) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FMAF(...) __builtin_fmaf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FMA(...) __builtin_fma(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FMAL(...) __builtin_fmal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_fmax)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float fma(float __x, float __y, float __z) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMAF)
|
||||
return _CCCL_BUILTIN_FMAF(__x, __y, __z);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMAF ^^^ / vvv !_CCCL_BUILTIN_FMAF vvv
|
||||
return ::fmaf(__x, __y, __z);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMAF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float fmaf(float __x, float __y, float __z) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMAF)
|
||||
return _CCCL_BUILTIN_FMAF(__x, __y, __z);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMAF ^^^ / vvv !_CCCL_BUILTIN_FMAF vvv
|
||||
return ::fmaf(__x, __y, __z);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMAF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double fma(double __x, double __y, double __z) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMA)
|
||||
return _CCCL_BUILTIN_FMA(__x, __y, __z);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMA ^^^ / vvv !_CCCL_BUILTIN_FMA vvv
|
||||
return ::fma(__x, __y, __z);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMA ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double fma(long double __x, long double __y, long double __z) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FMAL)
|
||||
return _CCCL_BUILTIN_FMAL(__x, __y, __z);
|
||||
# else // ^^^ _CCCL_BUILTIN_FMAL ^^^ / vvv !_CCCL_BUILTIN_FMAL vvv
|
||||
return ::fmal(__x, __y, __z);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FMAL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double fmal(long double __x, long double __y, long double __z) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FMAL)
|
||||
return _CCCL_BUILTIN_FMAL(__x, __y, __z);
|
||||
# else // ^^^ _CCCL_BUILTIN_FMAL ^^^ / vvv !_CCCL_BUILTIN_FMAL vvv
|
||||
return ::fmal(__x, __y, __z);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FMAL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half fma(__half __x, __half __y, __half __z) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_PROVIDES_SM_53,
|
||||
(return ::__hfma(__x, __y, __z);),
|
||||
(return ::__float2half(::cuda::std::fma(::__half2float(__x), ::__half2float(__y), ::__half2float(__z)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16
|
||||
fma(__nv_bfloat16 __x, __nv_bfloat16 __y, __nv_bfloat16 __z) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_PROVIDES_SM_80,
|
||||
(return ::__hfma(__x, __y, __z);),
|
||||
(return ::__float2bfloat16(
|
||||
::cuda::std::fma(::__bfloat162float(__x), ::__bfloat162float(__y), ::__bfloat162float(__z)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1,
|
||||
class _A2,
|
||||
class _A3,
|
||||
enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __promote_t<_A1, _A2, _A3> fma(_A1 __x, _A2 __y, _A3 __z) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2, _A3>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type> && is_same_v<_A3, __result_type>) );
|
||||
return ::cuda::std::fma((__result_type) __x, (__result_type) __y, (__result_type) __z);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_FMA_H
|
||||
233
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fpclassify.h
Normal file
233
cccl_upstream/libcudacxx/include/cuda/std/__cmath/fpclassify.h
Normal file
@@ -0,0 +1,233 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_FPCLASSIFY_H
|
||||
#define _CUDA_STD___CMATH_FPCLASSIFY_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__bit/bit_cast.h>
|
||||
#include <cuda/std/__cmath/isinf.h>
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
#if _CCCL_FREESTANDING()
|
||||
# ifndef FP_NAN
|
||||
# define FP_NAN 0
|
||||
# endif // ! FP_NAN
|
||||
# ifndef FP_INFINITE
|
||||
# define FP_INFINITE 1
|
||||
# endif // ! FP_INFINITE
|
||||
# ifndef FP_ZERO
|
||||
# define FP_ZERO 2
|
||||
# endif // ! FP_ZERO
|
||||
# ifndef FP_SUBNORMAL
|
||||
# define FP_SUBNORMAL 3
|
||||
# endif // ! FP_SUBNORMAL
|
||||
# ifndef FP_NORMAL
|
||||
# define FP_NORMAL 4
|
||||
# endif // ! FP_NORMAL
|
||||
#endif // _CCCL_FREESTANDING()
|
||||
|
||||
#ifndef FP_ILOGB0
|
||||
# define FP_ILOGB0 (-INT_MAX - 1)
|
||||
# define FP_LLOGB0 (-LONG_MAX - 1)
|
||||
#endif // !FP_ILOGB0
|
||||
|
||||
#ifndef FP_ILOGBNAN
|
||||
# ifdef __FP_LOGBNAN_MIN
|
||||
# define FP_ILOGBNAN (-INT_MAX - 1)
|
||||
# define FP_LLOGBNAN (-LONG_MAX - 1)
|
||||
# else // ^^^ __FP_LOGBNAN_MIN ^^^ / vvv !__FP_LOGBNAN_MIN vvv
|
||||
# define FP_ILOGBNAN INT_MAX
|
||||
# define FP_LLOGBNAN LONG_MAX
|
||||
# endif // !__FP_LOGBNAN_MIN
|
||||
#endif // !FP_ILOGBNAN
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fpclassify) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FPCLASSIFY(...) __builtin_fpclassify(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_fpclassify)
|
||||
|
||||
// nvcc does not implement __builtin_fpclassify
|
||||
#if _CCCL_CUDA_COMPILER(NVCC)
|
||||
# undef _CCCL_BUILTIN_FPCLASSIFY
|
||||
#endif // _CCCL_CUDA_COMPILER(NVCC)
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API constexpr int __fpclassify_impl(_Tp __x) noexcept
|
||||
{
|
||||
static_assert(__fp_has_denorm_v<__fp_format_of_v<_Tp>>, "The type must have denorm support");
|
||||
|
||||
if constexpr (numeric_limits<_Tp>::has_quiet_NaN || numeric_limits<_Tp>::has_signaling_NaN)
|
||||
{
|
||||
if (::cuda::std::isnan(__x))
|
||||
{
|
||||
return FP_NAN;
|
||||
}
|
||||
}
|
||||
if constexpr (numeric_limits<_Tp>::has_infinity)
|
||||
{
|
||||
if (::cuda::std::isinf(__x))
|
||||
{
|
||||
return FP_INFINITE;
|
||||
}
|
||||
}
|
||||
// comparison based classification keeps this path constexpr for types whose storage would need bit_cast
|
||||
if constexpr (is_floating_point_v<_Tp> || __is_ext_compiler_fp_v<_Tp>)
|
||||
{
|
||||
if (__x > -numeric_limits<_Tp>::min() && __x < numeric_limits<_Tp>::min())
|
||||
{
|
||||
return (__x == _Tp{}) ? FP_ZERO : FP_SUBNORMAL;
|
||||
}
|
||||
return FP_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto __storage = ::cuda::std::__fp_get_storage(__x);
|
||||
if ((__storage & __fp_exp_mask_of_v<_Tp>) == 0)
|
||||
{
|
||||
return (__storage & __fp_mant_mask_of_v<_Tp>) ? FP_SUBNORMAL : FP_ZERO;
|
||||
}
|
||||
return FP_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FPCLASSIFY)
|
||||
return _CCCL_BUILTIN_FPCLASSIFY(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_FPCLASSIFY ^^^ / vvv !_CCCL_BUILTIN_FPCLASSIFY vvv
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_IS_HOST, (return ::fpclassify(__x);))
|
||||
}
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
#endif // !_CCCL_BUILTIN_FPCLASSIFY
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FPCLASSIFY)
|
||||
return _CCCL_BUILTIN_FPCLASSIFY(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_FPCLASSIFY ^^^ / vvv !_CCCL_BUILTIN_FPCLASSIFY vvv
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_IS_HOST, (return ::fpclassify(__x);))
|
||||
}
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
#endif // !_CCCL_BUILTIN_FPCLASSIFY
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FPCLASSIFY)
|
||||
return _CCCL_BUILTIN_FPCLASSIFY(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
|
||||
# else // ^^^ _CCCL_BUILTIN_FPCLASSIFY ^^^ / vvv !_CCCL_BUILTIN_FPCLASSIFY vvv
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_IS_HOST, (return ::fpclassify(__x);))
|
||||
}
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
# endif // !_CCCL_BUILTIN_FPCLASSIFY
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E4M3()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp8_e4m3 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E4M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E5M2()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp8_e5m2 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E5M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E8M0()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp8_e8m0 __x) noexcept
|
||||
{
|
||||
return (__x.__x == __fp_exp_mask_of_v<__nv_fp8_e8m0>) ? FP_NAN : FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E8M0()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E2M3()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp6_e2m3 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E2M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E3M2()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp6_e3m2 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E3M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP4_E2M1()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__nv_fp4_e2m1 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP4_E2M1()
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(__float128 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__fpclassify_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr int fpclassify(_Tp __x) noexcept
|
||||
{
|
||||
return (__x == 0) ? FP_ZERO : FP_NORMAL;
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_FPCLASSIFY_H
|
||||
201
cccl_upstream/libcudacxx/include/cuda/std/__cmath/gamma.h
Normal file
201
cccl_upstream/libcudacxx/include/cuda/std/__cmath/gamma.h
Normal file
@@ -0,0 +1,201 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_GAMMA_H
|
||||
#define _CUDA_STD___CMATH_GAMMA_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// lgamma
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_lgamma) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LGAMMAF(...) __builtin_lgammaf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LGAMMA(...) __builtin_lgamma(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LGAMMAL(...) __builtin_lgammal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_lgamma)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LGAMMAF
|
||||
# undef _CCCL_BUILTIN_LGAMMA
|
||||
# undef _CCCL_BUILTIN_LGAMMAL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float lgamma(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LGAMMAF)
|
||||
return _CCCL_BUILTIN_LGAMMAF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LGAMMAF ^^^ / vvv !_CCCL_BUILTIN_LGAMMAF vvv
|
||||
return ::lgammaf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LGAMMAF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float lgammaf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LGAMMAF)
|
||||
return _CCCL_BUILTIN_LGAMMAF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LGAMMAF ^^^ / vvv !_CCCL_BUILTIN_LGAMMAF vvv
|
||||
return ::lgammaf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LGAMMAF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double lgamma(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LGAMMA)
|
||||
return _CCCL_BUILTIN_LGAMMA(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LGAMMA ^^^ / vvv !_CCCL_BUILTIN_LGAMMA vvv
|
||||
return ::lgamma(__x);
|
||||
#endif // !_CCCL_BUILTIN_LGAMMA
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double lgamma(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LGAMMAL)
|
||||
return _CCCL_BUILTIN_LGAMMAL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LGAMMAL ^^^ / vvv !_CCCL_BUILTIN_LGAMMAL vvv
|
||||
return ::lgammal(__x);
|
||||
# endif // !_CCCL_BUILTIN_LGAMMAL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double lgammal(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LGAMMAL)
|
||||
return _CCCL_BUILTIN_LGAMMAL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LGAMMAL ^^^ / vvv !_CCCL_BUILTIN_LGAMMAL vvv
|
||||
return ::lgammal(__x);
|
||||
# endif // !_CCCL_BUILTIN_LGAMMAL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half lgamma(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::lgammaf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 lgamma(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::lgammaf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double lgamma(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lgamma((double) __x);
|
||||
}
|
||||
|
||||
// tgamma
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_tgamma) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_TGAMMAF(...) __builtin_tgammaf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TGAMMA(...) __builtin_tgamma(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TGAMMAL(...) __builtin_tgammal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_tgamma)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_TGAMMAF
|
||||
# undef _CCCL_BUILTIN_TGAMMA
|
||||
# undef _CCCL_BUILTIN_TGAMMAL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float tgamma(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TGAMMAF)
|
||||
return _CCCL_BUILTIN_TGAMMAF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TGAMMAF ^^^ / vvv !_CCCL_BUILTIN_TGAMMAF vvv
|
||||
return ::tgammaf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TGAMMAF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float tgammaf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TGAMMAF)
|
||||
return _CCCL_BUILTIN_TGAMMAF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TGAMMAF ^^^ / vvv !_CCCL_BUILTIN_TGAMMAF vvv
|
||||
return ::tgammaf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TGAMMAF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double tgamma(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TGAMMA)
|
||||
return _CCCL_BUILTIN_TGAMMA(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TGAMMA ^^^ / vvv !_CCCL_BUILTIN_TGAMMA vvv
|
||||
return ::tgamma(__x);
|
||||
#endif // !_CCCL_BUILTIN_TGAMMA
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double tgamma(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TGAMMAL)
|
||||
return _CCCL_BUILTIN_TGAMMAL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TGAMMAL ^^^ / vvv !_CCCL_BUILTIN_TGAMMAL vvv
|
||||
return ::tgammal(__x);
|
||||
# endif // !_CCCL_BUILTIN_TGAMMAL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double tgammal(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TGAMMAL)
|
||||
return _CCCL_BUILTIN_TGAMMAL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TGAMMAL ^^^ / vvv !_CCCL_BUILTIN_TGAMMAL vvv
|
||||
return ::tgammal(__x);
|
||||
# endif // !_CCCL_BUILTIN_TGAMMAL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half tgamma(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::tgammaf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 tgamma(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::tgammaf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double tgamma(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::tgamma((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_GAMMA_H
|
||||
@@ -0,0 +1,282 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_HYPERBOLIC_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_HYPERBOLIC_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// cosh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_cosh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_COSHF(...) __builtin_coshf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_COSH(...) __builtin_cosh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_COSHL(...) __builtin_coshl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_cosh)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_COSHF
|
||||
# undef _CCCL_BUILTIN_COSH
|
||||
# undef _CCCL_BUILTIN_COSHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float cosh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COSHF)
|
||||
return _CCCL_BUILTIN_COSHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COSHF ^^^ / vvv !_CCCL_BUILTIN_COSHF vvv
|
||||
return ::coshf(__x);
|
||||
#endif // !_CCCL_BUILTIN_COSHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float coshf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COSHF)
|
||||
return _CCCL_BUILTIN_COSHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COSHF ^^^ / vvv !_CCCL_BUILTIN_COSHF vvv
|
||||
return ::coshf(__x);
|
||||
#endif // !_CCCL_BUILTIN_COSHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double cosh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COSH)
|
||||
return _CCCL_BUILTIN_COSH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COSH ^^^ / vvv !_CCCL_BUILTIN_COSH vvv
|
||||
return ::cosh(__x);
|
||||
#endif // !_CCCL_BUILTIN_COSH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double cosh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_COSHL)
|
||||
return _CCCL_BUILTIN_COSHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_COSHL ^^^ / vvv !_CCCL_BUILTIN_COSHL vvv
|
||||
return ::coshl(__x);
|
||||
# endif // !_CCCL_BUILTIN_COSHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double coshl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_COSHL)
|
||||
return _CCCL_BUILTIN_COSHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_COSHL ^^^ / vvv !_CCCL_BUILTIN_COSHL vvv
|
||||
return ::coshl(__x);
|
||||
# endif // !_CCCL_BUILTIN_COSHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half cosh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::coshf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 cosh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::coshf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double cosh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::cosh((double) __x);
|
||||
}
|
||||
|
||||
// sinh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_sinh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_SINHF(...) __builtin_sinhf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SINH(...) __builtin_sinh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SINHL(...) __builtin_sinhl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_sin)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_SINHF
|
||||
# undef _CCCL_BUILTIN_SINH
|
||||
# undef _CCCL_BUILTIN_SINHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float sinh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SINHF)
|
||||
return _CCCL_BUILTIN_SINHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SINHF ^^^ / vvv !_CCCL_BUILTIN_SINHF vvv
|
||||
return ::sinhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SINHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float sinhf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SINHF)
|
||||
return _CCCL_BUILTIN_SINHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SINHF ^^^ / vvv !_CCCL_BUILTIN_SINHF vvv
|
||||
return ::sinhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SINHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double sinh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SINH)
|
||||
return _CCCL_BUILTIN_SINH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SINH ^^^ / vvv !_CCCL_BUILTIN_SINH vvv
|
||||
return ::sinh(__x);
|
||||
#endif // !_CCCL_BUILTIN_SINH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double sinh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SINHL)
|
||||
return _CCCL_BUILTIN_SINHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SINHL ^^^ / vvv !_CCCL_BUILTIN_SINHL vvv
|
||||
return ::sinhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SINHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double sinhl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SINHL)
|
||||
return _CCCL_BUILTIN_SINHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SINHL ^^^ / vvv !_CCCL_BUILTIN_SINHL vvv
|
||||
return ::sinhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SINHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half sinh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::sinhf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 sinh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::sinhf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double sinh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::sinh((double) __x);
|
||||
}
|
||||
|
||||
// tanh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_tanh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_TANHF(...) __builtin_tanhf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TANH(...) __builtin_tanh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TANHL(...) __builtin_tanhl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_tan)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_TANHF
|
||||
# undef _CCCL_BUILTIN_TANH
|
||||
# undef _CCCL_BUILTIN_TANHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float tanh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TANHF)
|
||||
return _CCCL_BUILTIN_TANHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TANHF ^^^ / vvv !_CCCL_BUILTIN_TANHF vvv
|
||||
return ::tanhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TANHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float tanhf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TANHF)
|
||||
return _CCCL_BUILTIN_TANHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TANHF ^^^ / vvv !_CCCL_BUILTIN_TANHF vvv
|
||||
return ::tanhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TANHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double tanh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TANH)
|
||||
return _CCCL_BUILTIN_TANH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TANH ^^^ / vvv !_CCCL_BUILTIN_TANH vvv
|
||||
return ::tanh(__x);
|
||||
#endif // !_CCCL_BUILTIN_TANH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double tanh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TANHL)
|
||||
return _CCCL_BUILTIN_TANHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TANHL ^^^ / vvv !_CCCL_BUILTIN_TANHL vvv
|
||||
return ::tanhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TANHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double tanhl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TANHL)
|
||||
return _CCCL_BUILTIN_TANHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TANHL ^^^ / vvv !_CCCL_BUILTIN_TANHL vvv
|
||||
return ::tanhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TANHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half tanh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::tanhf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 tanh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::tanhf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double tanh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::tanh((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_HYPERBOLIC_FUNCTIONS_H
|
||||
218
cccl_upstream/libcudacxx/include/cuda/std/__cmath/hypot.h
Normal file
218
cccl_upstream/libcudacxx/include/cuda/std/__cmath/hypot.h
Normal file
@@ -0,0 +1,218 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_HYPOT_H
|
||||
#define _CUDA_STD___CMATH_HYPOT_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/abs.h>
|
||||
#include <cuda/std/__cmath/exponential_functions.h>
|
||||
#include <cuda/std/__cmath/min_max.h>
|
||||
#include <cuda/std/__cmath/roots.h>
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// hypot
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_hypot) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_HYPOTF(...) __builtin_hypotf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_HYPOT(...) __builtin_hypot(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_HYPOTL(...) __builtin_hypotl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_hypot)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_HYPOTF
|
||||
# undef _CCCL_BUILTIN_HYPOT
|
||||
# undef _CCCL_BUILTIN_HYPOTL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float hypot(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_HYPOTF)
|
||||
return _CCCL_BUILTIN_HYPOTF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_HYPOTF ^^^ // vvv !_CCCL_BUILTIN_HYPOTF vvv
|
||||
return ::hypotf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_HYPOTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float hypotf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_HYPOTF)
|
||||
return _CCCL_BUILTIN_HYPOTF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_HYPOTF ^^^ // vvv !_CCCL_BUILTIN_HYPOTF vvv
|
||||
return ::hypotf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_HYPOTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double hypot(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_HYPOT)
|
||||
return _CCCL_BUILTIN_HYPOT(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_HYPOT ^^^ // vvv !_CCCL_BUILTIN_HYPOT vvv
|
||||
return ::hypot(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_HYPOT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double hypot(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_HYPOTL)
|
||||
return _CCCL_BUILTIN_HYPOTL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_HYPOTL ^^^ // vvv !_CCCL_BUILTIN_HYPOTL vvv
|
||||
return ::hypotl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_HYPOTL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double hypotl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_HYPOTL)
|
||||
return _CCCL_BUILTIN_HYPOTL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_HYPOTL ^^^ // vvv !_CCCL_BUILTIN_HYPOTL vvv
|
||||
return ::hypotl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_HYPOTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half hypot(__half __x, __half __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::hypotf(__half2float(__x), __half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 hypot(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::hypotf(__bfloat162float(__x), __bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __promote_t<_A1, _A2> hypot(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::hypot((__result_type) __x, (__result_type) __y);
|
||||
}
|
||||
|
||||
// hypot 3-arg
|
||||
|
||||
// Computes the three-dimensional hypotenuse: `std::hypot(x,y,z)`.
|
||||
// The naive implementation might over-/underflow which is why this implementation is more involved:
|
||||
// If the square of an argument might run into issues, we scale the arguments appropriately.
|
||||
// See https://github.com/llvm/llvm-project/issues/92782 for a detailed discussion and summary.
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline _Tp __hypot(_Tp __x, _Tp __y, _Tp __z)
|
||||
{
|
||||
// Factors needed to determine if over-/underflow might happen
|
||||
constexpr int __exp = ::cuda::std::numeric_limits<_Tp>::max_exponent / 2;
|
||||
const _Tp __overflow_threshold = ::cuda::std::ldexp(_Tp(1), __exp);
|
||||
const _Tp __overflow_scale = ::cuda::std::ldexp(_Tp(1), -(__exp + 20));
|
||||
|
||||
// Scale arguments depending on their size
|
||||
const _Tp __max_abs =
|
||||
::cuda::std::fmax(::cuda::std::fabs(__x), ::cuda::std::fmax(::cuda::std::fabs(__y), ::cuda::std::fabs(__z)));
|
||||
_Tp __scale;
|
||||
if (__max_abs > __overflow_threshold)
|
||||
{ // x*x + y*y + z*z might overflow
|
||||
__scale = __overflow_scale;
|
||||
}
|
||||
else if (__max_abs < 1 / __overflow_threshold)
|
||||
{ // x*x + y*y + z*z might underflow
|
||||
__scale = 1 / __overflow_scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
__scale = 1;
|
||||
}
|
||||
__x *= __scale;
|
||||
__y *= __scale;
|
||||
__z *= __scale;
|
||||
|
||||
// Compute hypot of scaled arguments and undo scaling
|
||||
return ::cuda::std::sqrt(__x * __x + __y * __y + __z * __z) / __scale;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float hypot(float __x, float __y, float __z) noexcept
|
||||
{
|
||||
return ::cuda::std::__hypot(__x, __y, __z);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float hypotf(float __x, float __y, float __z) noexcept
|
||||
{
|
||||
return ::cuda::std::__hypot(__x, __y, __z);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double hypot(double __x, double __y, double __z) noexcept
|
||||
{
|
||||
return ::cuda::std::__hypot(__x, __y, __z);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double hypot(long double __x, long double __y, long double __z) noexcept
|
||||
{
|
||||
return ::cuda::std::__hypot(__x, __y, __z);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double hypotl(long double __x, long double __y, long double __z) noexcept
|
||||
{
|
||||
return ::cuda::std::__hypot(__x, __y, __z);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half hypot(__half __x, __half __y, __half __z) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::__hypot(__half2float(__x), __half2float(__y), __half2float(__z)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16
|
||||
hypot(__nv_bfloat16 __x, __nv_bfloat16 __y, __nv_bfloat16 __z) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::__hypot(__bfloat162float(__x), __bfloat162float(__y), __bfloat162float(__z)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
_CCCL_TEMPLATE(class _A1, class _A2, class _A3)
|
||||
_CCCL_REQUIRES(is_arithmetic_v<_A1> _CCCL_AND is_arithmetic_v<_A2> _CCCL_AND is_arithmetic_v<_A3>)
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __promote_t<_A1, _A2, _A3> hypot(_A1 __x, _A2 __y, _A3 __z) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2, _A3>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type> && is_same_v<_A3, __result_type>) );
|
||||
return ::cuda::std::hypot((__result_type) __x, (__result_type) __y, (__result_type) __z);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_HYPOT_H
|
||||
@@ -0,0 +1,282 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_INVERSE_HYPERBOLIC_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_INVERSE_HYPERBOLIC_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// acosh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_acosh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ACOSHF(...) __builtin_acoshf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ACOSH(...) __builtin_acosh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ACOSHL(...) __builtin_acoshl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_acosh)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ACOSHF
|
||||
# undef _CCCL_BUILTIN_ACOSH
|
||||
# undef _CCCL_BUILTIN_ACOSHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float acosh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOSHF)
|
||||
return _CCCL_BUILTIN_ACOSHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOSHF ^^^ / vvv !_CCCL_BUILTIN_ACOSHF vvv
|
||||
return ::acoshf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOSHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float acoshf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOSHF)
|
||||
return _CCCL_BUILTIN_ACOSHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOSHF ^^^ / vvv !_CCCL_BUILTIN_ACOSHF vvv
|
||||
return ::acoshf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOSHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double acosh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOSH)
|
||||
return _CCCL_BUILTIN_ACOSH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOSH ^^^ / vvv !_CCCL_BUILTIN_ACOSH vvv
|
||||
return ::acosh(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOSH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double acosh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ACOSHL)
|
||||
return _CCCL_BUILTIN_ACOSHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ACOSHL ^^^ / vvv !_CCCL_BUILTIN_ACOSHL vvv
|
||||
return ::acoshl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ACOSHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double acoshl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ACOSHL)
|
||||
return _CCCL_BUILTIN_ACOSHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ACOSHL ^^^ / vvv !_CCCL_BUILTIN_ACOSHL vvv
|
||||
return ::acoshl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ACOSHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half acosh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::acoshf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 acosh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::acoshf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double acosh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::acosh((double) __x);
|
||||
}
|
||||
|
||||
// asinh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_asinh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ASINHF(...) __builtin_asinhf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ASINH(...) __builtin_asinh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ASINHL(...) __builtin_asinhl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_asin)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ASINHF
|
||||
# undef _CCCL_BUILTIN_ASINH
|
||||
# undef _CCCL_BUILTIN_ASINHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float asinh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASINHF)
|
||||
return _CCCL_BUILTIN_ASINHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASINHF ^^^ / vvv !_CCCL_BUILTIN_ASINHF vvv
|
||||
return ::asinhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASINHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float asinhf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASINHF)
|
||||
return _CCCL_BUILTIN_ASINHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASINHF ^^^ / vvv !_CCCL_BUILTIN_ASINHF vvv
|
||||
return ::asinhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASINHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double asinh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASINH)
|
||||
return _CCCL_BUILTIN_ASINH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASINH ^^^ / vvv !_CCCL_BUILTIN_ASINH vvv
|
||||
return ::asinh(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASINH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double asinh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ASINHL)
|
||||
return _CCCL_BUILTIN_ASINHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ASINHL ^^^ / vvv !_CCCL_BUILTIN_ASINHL vvv
|
||||
return ::asinhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ASINHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double asinhl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ASINHL)
|
||||
return _CCCL_BUILTIN_ASINHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ASINHL ^^^ / vvv !_CCCL_BUILTIN_ASINHL vvv
|
||||
return ::asinhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ASINHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half asinh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::asinhf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 asinh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::asinhf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double asinh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::asinh((double) __x);
|
||||
}
|
||||
|
||||
// atanh
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_atanh) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ATANHF(...) __builtin_atanhf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATANH(...) __builtin_atanh(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATANHL(...) __builtin_atanhl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_atanh)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ATANHF
|
||||
# undef _CCCL_BUILTIN_ATANH
|
||||
# undef _CCCL_BUILTIN_ATANHL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atanh(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATANHF)
|
||||
return _CCCL_BUILTIN_ATANHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATANHF ^^^ / vvv !_CCCL_BUILTIN_ATANHF vvv
|
||||
return ::atanhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATANHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atanhf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATANHF)
|
||||
return _CCCL_BUILTIN_ATANHF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATANHF ^^^ / vvv !_CCCL_BUILTIN_ATANHF vvv
|
||||
return ::atanhf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATANHF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double atanh(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATANH)
|
||||
return _CCCL_BUILTIN_ATANH(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATANH ^^^ / vvv !_CCCL_BUILTIN_ATANH vvv
|
||||
return ::atanh(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATANH
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atanh(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATANHL)
|
||||
return _CCCL_BUILTIN_ATANHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATANHL ^^^ / vvv !_CCCL_BUILTIN_ATANHL vvv
|
||||
return ::atanhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ATANHL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atanhl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATANHL)
|
||||
return _CCCL_BUILTIN_ATANHL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATANHL ^^^ / vvv !_CCCL_BUILTIN_ATANHL vvv
|
||||
return ::atanhl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ATANHL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half atanh(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::atanhf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 atanh(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::atanhf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double atanh(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::atanh((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_INVERSE_HYPERBOLIC_FUNCTIONS_H
|
||||
@@ -0,0 +1,367 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// acos
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_acos) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ACOSF(...) __builtin_acosf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ACOS(...) __builtin_acos(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ACOSL(...) __builtin_acosl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_acos)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ACOSF
|
||||
# undef _CCCL_BUILTIN_ACOS
|
||||
# undef _CCCL_BUILTIN_ACOSL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float acos(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOSF)
|
||||
return _CCCL_BUILTIN_ACOSF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOSF ^^^ / vvv !_CCCL_BUILTIN_ACOSF vvv
|
||||
return ::acosf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOSF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float acosf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOSF)
|
||||
return _CCCL_BUILTIN_ACOSF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOSF ^^^ / vvv !_CCCL_BUILTIN_ACOSF vvv
|
||||
return ::acosf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOSF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double acos(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ACOS)
|
||||
return _CCCL_BUILTIN_ACOS(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ACOS ^^^ / vvv !_CCCL_BUILTIN_ACOS vvv
|
||||
return ::acos(__x);
|
||||
#endif // !_CCCL_BUILTIN_ACOS
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double acos(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ACOSL)
|
||||
return _CCCL_BUILTIN_ACOSL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ACOSL ^^^ / vvv !_CCCL_BUILTIN_ACOSL vvv
|
||||
return ::acosl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ACOSL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double acosl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ACOSL)
|
||||
return _CCCL_BUILTIN_ACOSL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ACOSL ^^^ / vvv !_CCCL_BUILTIN_ACOSL vvv
|
||||
return ::acosl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ACOSL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half acos(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::acosf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 acos(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::acosf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double acos(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::acos((double) __x);
|
||||
}
|
||||
|
||||
// asin
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_asin) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ASINF(...) __builtin_asinf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ASIN(...) __builtin_asin(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ASINL(...) __builtin_asinl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_asin)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ASINF
|
||||
# undef _CCCL_BUILTIN_ASIN
|
||||
# undef _CCCL_BUILTIN_ASINL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float asin(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASINF)
|
||||
return _CCCL_BUILTIN_ASINF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASINF ^^^ / vvv !_CCCL_BUILTIN_ASINF vvv
|
||||
return ::asinf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASINF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float asinf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASINF)
|
||||
return _CCCL_BUILTIN_ASINF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASINF ^^^ / vvv !_CCCL_BUILTIN_ASINF vvv
|
||||
return ::asinf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASINF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double asin(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ASIN)
|
||||
return _CCCL_BUILTIN_ASIN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ASIN ^^^ / vvv !_CCCL_BUILTIN_ASIN vvv
|
||||
return ::asin(__x);
|
||||
#endif // !_CCCL_BUILTIN_ASIN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double asin(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ASINL)
|
||||
return _CCCL_BUILTIN_ASINL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ASINL ^^^ / vvv !_CCCL_BUILTIN_ASINL vvv
|
||||
return ::asinl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ASINL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double asinl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ASINL)
|
||||
return _CCCL_BUILTIN_ASINL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ASINL ^^^ / vvv !_CCCL_BUILTIN_ASINL vvv
|
||||
return ::asinl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ASINL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half asin(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::asinf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 asin(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::asinf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double asin(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::asin((double) __x);
|
||||
}
|
||||
|
||||
// atan
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_atan) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ATANF(...) __builtin_atanf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATAN(...) __builtin_atan(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATANL(...) __builtin_atanl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_atan)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ATANF
|
||||
# undef _CCCL_BUILTIN_ATAN
|
||||
# undef _CCCL_BUILTIN_ATANL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atan(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATANF)
|
||||
return _CCCL_BUILTIN_ATANF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATANF ^^^ / vvv !_CCCL_BUILTIN_ATANF vvv
|
||||
return ::atanf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATANF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atanf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATANF)
|
||||
return _CCCL_BUILTIN_ATANF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATANF ^^^ / vvv !_CCCL_BUILTIN_ATANF vvv
|
||||
return ::atanf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATANF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double atan(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATAN)
|
||||
return _CCCL_BUILTIN_ATAN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATAN ^^^ / vvv !_CCCL_BUILTIN_ATAN vvv
|
||||
return ::atan(__x);
|
||||
#endif // !_CCCL_BUILTIN_ATAN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atan(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATANL)
|
||||
return _CCCL_BUILTIN_ATANL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATANL ^^^ / vvv !_CCCL_BUILTIN_ATANL vvv
|
||||
return ::atanl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ATANL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atanl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATANL)
|
||||
return _CCCL_BUILTIN_ATANL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATANL ^^^ / vvv !_CCCL_BUILTIN_ATANL vvv
|
||||
return ::atanl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ATANL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half atan(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::atanf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 atan(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::atanf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double atan(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::atan((double) __x);
|
||||
}
|
||||
|
||||
// atan2
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_atan2) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ATAN2F(...) __builtin_atan2f(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATAN2(...) __builtin_atan2(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ATAN2L(...) __builtin_atan2l(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_atan2)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_ATAN2F
|
||||
# undef _CCCL_BUILTIN_ATAN2
|
||||
# undef _CCCL_BUILTIN_ATAN2L
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atan2(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATAN2F)
|
||||
return _CCCL_BUILTIN_ATAN2F(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATAN2F ^^^ // vvv !_CCCL_BUILTIN_ATAN2F vvv
|
||||
return ::atan2f(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_ATAN2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline float atan2f(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATAN2F)
|
||||
return _CCCL_BUILTIN_ATAN2F(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATAN2F ^^^ // vvv !_CCCL_BUILTIN_ATAN2F vvv
|
||||
return ::atan2f(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_ATAN2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline double atan2(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ATAN2)
|
||||
return _CCCL_BUILTIN_ATAN2(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_ATAN2 ^^^ // vvv !_CCCL_BUILTIN_ATAN2 vvv
|
||||
return ::atan2(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_ATAN2
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atan2(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATAN2L)
|
||||
return _CCCL_BUILTIN_ATAN2L(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATAN2L ^^^ // vvv !_CCCL_BUILTIN_ATAN2L vvv
|
||||
return ::atan2l(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ATAN2L
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline long double atan2l(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ATAN2L)
|
||||
return _CCCL_BUILTIN_ATAN2L(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ATAN2L ^^^ // vvv !_CCCL_BUILTIN_ATAN2L vvv
|
||||
return ::atan2l(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ATAN2L
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __half atan2(__half __x, __half __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::atan2f(__half2float(__x), __half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __nv_bfloat16 atan2(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::atan2f(__bfloat162float(__x), __bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_DEVICE_API inline __promote_t<_A1, _A2> atan2(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::atan2((__result_type) __x, (__result_type) __y);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_INVERSE_TRIGONOMETRIC_FUNCTIONS_H
|
||||
186
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isfinite.h
Normal file
186
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isfinite.h
Normal file
@@ -0,0 +1,186 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ISFINITE_H
|
||||
#define _CUDA_STD___CMATH_ISFINITE_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__bit/bit_cast.h>
|
||||
#include <cuda/std/__cmath/isinf.h>
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_extended_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isfinite) || _CCCL_COMPILER(GCC) || _CCCL_COMPILER(NVRTC, >, 12, 2)
|
||||
# define _CCCL_BUILTIN_ISFINITE(...) __builtin_isfinite(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(isfinite)
|
||||
|
||||
#if _CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
# undef _CCCL_BUILTIN_ISFINITE
|
||||
#endif // _CCCL_TILE_COMPILATION()
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API constexpr bool __isfinite_impl(_Tp __x) noexcept
|
||||
{
|
||||
static_assert(is_floating_point_v<_Tp> || __is_extended_floating_point_v<_Tp>,
|
||||
"Only floating-point types are supported");
|
||||
if constexpr (is_floating_point_v<_Tp>)
|
||||
{
|
||||
#if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isfinite(__x);
|
||||
}
|
||||
#endif // !_CCCL_TILE_COMPILATION()
|
||||
}
|
||||
return !::cuda::std::isnan(__x) && !::cuda::std::isinf(__x);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISFINITE)
|
||||
return _CCCL_BUILTIN_ISFINITE(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISFINITE ^^^ / vvv !_CCCL_BUILTIN_ISFINITE vvv
|
||||
# if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isfinite(__x);
|
||||
}
|
||||
# endif // !_CCCL_TILE_COMPILATION()
|
||||
# if _CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mask_of_v<float>) != __fp_exp_mask_of_v<float>;
|
||||
# else // ^^^ _CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^ / vvv !_CCCL_HAS_CONSTEXPR_BIT_CAST() vvv
|
||||
return ::cuda::std::__isfinite_impl(__x);
|
||||
# endif // ^^^ !_CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISFINITE ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISFINITE)
|
||||
return _CCCL_BUILTIN_ISFINITE(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISFINITE ^^^ / vvv !_CCCL_BUILTIN_ISFINITE vvv
|
||||
# if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isfinite(__x);
|
||||
}
|
||||
# endif // !_CCCL_TILE_COMPILATION()
|
||||
# if _CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mask_of_v<double>) != __fp_exp_mask_of_v<double>;
|
||||
# else // ^^^ _CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^ / vvv !_CCCL_HAS_CONSTEXPR_BIT_CAST() vvv
|
||||
return ::cuda::std::__isfinite_impl(__x);
|
||||
# endif // ^^^ !_CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISFINITE ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISFINITE)
|
||||
return _CCCL_BUILTIN_ISFINITE(__x);
|
||||
# else
|
||||
return ::cuda::std::__isfinite_impl(__x);
|
||||
# endif // defined(_CCCL_BUILTIN_ISFINITE)
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__half __x) noexcept
|
||||
{
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mask_of_v<__half>) != __fp_exp_mask_of_v<__half>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mask_of_v<__nv_bfloat16>) != __fp_exp_mask_of_v<__nv_bfloat16>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E4M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp8_e4m3 __x) noexcept
|
||||
{
|
||||
return (__x.__x & __fp_exp_mant_mask_of_v<__nv_fp8_e4m3>) != __fp_exp_mant_mask_of_v<__nv_fp8_e4m3>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E4M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E5M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp8_e5m2 __x) noexcept
|
||||
{
|
||||
return (__x.__x & __fp_exp_mask_of_v<__nv_fp8_e5m2>) != __fp_exp_mask_of_v<__nv_fp8_e5m2>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E5M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E8M0()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp8_e8m0 __x) noexcept
|
||||
{
|
||||
return __x.__x != __fp_exp_mask_of_v<__nv_fp8_e8m0>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E8M0()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E2M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp6_e2m3) noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E2M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E3M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp6_e3m2) noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E3M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP4_E2M1()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__nv_fp4_e2m1) noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP4_E2M1()
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(__float128 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__isfinite_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr bool isfinite(_Tp) noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ISFINITE_H
|
||||
226
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isinf.h
Normal file
226
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isinf.h
Normal file
@@ -0,0 +1,226 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ISINF_H
|
||||
#define _CUDA_STD___CMATH_ISINF_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_extended_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isinf) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISINF(...) __builtin_isinf(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(isinf)
|
||||
|
||||
#if _CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
# undef _CCCL_BUILTIN_ISINF
|
||||
#endif // _CCCL_TILE_COMPILATION()
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API constexpr bool __isinf_impl(_Tp __x) noexcept
|
||||
{
|
||||
static_assert(is_floating_point_v<_Tp> || __is_extended_floating_point_v<_Tp>,
|
||||
"Only floating-point types are supported");
|
||||
if constexpr (is_floating_point_v<_Tp>)
|
||||
{
|
||||
#if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isinf(__x);
|
||||
}
|
||||
#endif // !_CCCL_TILE_COMPILATION()
|
||||
}
|
||||
if (::cuda::std::isnan(__x))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x > numeric_limits<_Tp>::max() || __x < numeric_limits<_Tp>::lowest();
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISINF) && !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_CUDA_COMPILER(NVRTC)
|
||||
return _CCCL_BUILTIN_ISINF(__x);
|
||||
#elif defined(_CCCL_BUILTIN_ISINF)
|
||||
// Workaround for nvbug 5120680
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return _CCCL_BUILTIN_ISINF(__x);
|
||||
}
|
||||
return _CCCL_BUILTIN_ISINF(__x) && !_CCCL_BUILTIN_ISNAN(__x);
|
||||
#elif _CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
# if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isinf(__x);
|
||||
}
|
||||
# endif // !_CCCL_TILE_COMPILATION()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<float>) == __fp_exp_mask_of_v<float>;
|
||||
#else // ^^^ _CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^ / vvv !_CCCL_HAS_CONSTEXPR_BIT_CAST() vvv
|
||||
return ::cuda::std::__isinf_impl(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISINF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISINF) && !_CCCL_CUDA_COMPILER(NVCC) && !_CCCL_CUDA_COMPILER(NVRTC)
|
||||
return _CCCL_BUILTIN_ISINF(__x);
|
||||
#elif defined(_CCCL_BUILTIN_ISINF)
|
||||
// Workaround for nvbug 5120680
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return _CCCL_BUILTIN_ISINF(__x);
|
||||
}
|
||||
return _CCCL_BUILTIN_ISINF(__x) && !_CCCL_BUILTIN_ISNAN(__x);
|
||||
#elif _CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
# if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isinf(__x);
|
||||
}
|
||||
# endif // !_CCCL_TILE_COMPILATION()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<double>) == __fp_exp_mask_of_v<double>;
|
||||
#else // ^^^ _CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^ / vvv !_CCCL_HAS_CONSTEXPR_BIT_CAST() vvv
|
||||
return ::cuda::std::__isinf_impl(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISINF ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISINF)
|
||||
return _CCCL_BUILTIN_ISINF(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISINF ^^^ / vvv !_CCCL_BUILTIN_ISINF vvv
|
||||
return ::cuda::std::__isinf_impl(__x);
|
||||
# endif // defined(_CCCL_BUILTIN_ISINF)
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__half __x) noexcept
|
||||
{
|
||||
# if _LIBCUDACXX_HAS_NVFP16()
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
# if _CCCL_STD_VER >= 2020 && _CCCL_CUDA_COMPILER(NVCC, <, 12, 3)
|
||||
// this is a workaround for nvbug 4362808
|
||||
return !::__hisnan(__x) && ::__hisnan(__x - __x);
|
||||
# else // ^^^ C++20 and nvcc below 12.3 ^^^ / vvv C++17 or nvcc 12.3+ vvv
|
||||
return ::__hisinf(__x) != 0;
|
||||
# endif // ^^^ C++17 or nvcc 12.3+ ^^^
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<__half>) == __fp_exp_mask_of_v<__half>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
# if _LIBCUDACXX_HAS_NVBF16()
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
# if _CCCL_STD_VER >= 2020 && _CCCL_CUDA_COMPILER(NVCC, <, 12, 3)
|
||||
// this is a workaround for nvbug 4362808
|
||||
return !::__hisnan(__x) && ::__hisnan(__x - __x);
|
||||
# else // ^^^ C++20 and nvcc below 12.3 ^^^ / vvv C++17 or nvcc 12.3+ vvv
|
||||
return ::__hisinf(__x) != 0;
|
||||
# endif // ^^^ C++17 or nvcc 12.3+ ^^^
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
return (::cuda::std::__fp_get_storage(__x) & __fp_exp_mant_mask_of_v<__nv_bfloat16>)
|
||||
== __fp_exp_mask_of_v<__nv_bfloat16>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E4M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp8_e4m3) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E4M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E5M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp8_e5m2 __x) noexcept
|
||||
{
|
||||
return (__x.__x & __fp_exp_mant_mask_of_v<__nv_fp8_e5m2>) == __fp_exp_mask_of_v<__nv_fp8_e5m2>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E5M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E8M0()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp8_e8m0) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E8M0()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E2M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp6_e2m3) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E2M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E3M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp6_e3m2) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E3M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP4_E2M1()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__nv_fp4_e2m1) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP4_E2M1()
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(__float128 __x) noexcept
|
||||
{
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_PROVIDES_SM_100, (return ::__nv_fp128_fabs(__x) == ::cuda::std::__fp_inf<__float128>();))
|
||||
}
|
||||
return ::cuda::std::__isinf_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr bool isinf(_Tp) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ISINF_H
|
||||
187
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isnan.h
Normal file
187
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isnan.h
Normal file
@@ -0,0 +1,187 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ISNAN_H
|
||||
#define _CUDA_STD___CMATH_ISNAN_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/is_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isnan) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISNAN(...) __builtin_isnan(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(isnan)
|
||||
|
||||
#if _CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
# undef _CCCL_BUILTIN_ISNAN
|
||||
#endif // _CCCL_TILE_COMPILATION()
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API constexpr bool __isnan_impl(_Tp __x) noexcept
|
||||
{
|
||||
static_assert(is_floating_point_v<_Tp>, "Only standard floating-point types are supported");
|
||||
#if !_CCCL_TILE_COMPILATION() // nvbug6077402: error: "call to non-tile function not supported!"
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::isnan(__x);
|
||||
}
|
||||
#endif // !_CCCL_TILE_COMPILATION()
|
||||
return __x != __x;
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISNAN)
|
||||
return _CCCL_BUILTIN_ISNAN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISNAN ^^^ / vvv !_CCCL_BUILTIN_ISNAN vvv
|
||||
return ::cuda::std::__isnan_impl(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISNAN ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISNAN)
|
||||
return _CCCL_BUILTIN_ISNAN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISNAN ^^^ / vvv !_CCCL_BUILTIN_ISNAN vvv
|
||||
return ::cuda::std::__isnan_impl(__x);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_ISNAN ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISNAN)
|
||||
return _CCCL_BUILTIN_ISNAN(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISNAN ^^^ / vvv !_CCCL_BUILTIN_ISNAN vvv
|
||||
return ::cuda::std::__isnan_impl(__x);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ISNAN ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__half __x) noexcept
|
||||
{
|
||||
# if _LIBCUDACXX_HAS_NVFP16()
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::__hisnan(__x);
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
const auto __storage = ::cuda::std::__fp_get_storage(__x);
|
||||
return ((__storage & __fp_exp_mask_of_v<__half>) == __fp_exp_mask_of_v<__half>)
|
||||
&& (__storage & __fp_mant_mask_of_v<__half>);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
# if _LIBCUDACXX_HAS_NVFP16()
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
return ::__hisnan(__x);
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
const auto __storage = ::cuda::std::__fp_get_storage(__x);
|
||||
return ((__storage & __fp_exp_mask_of_v<__nv_bfloat16>) == __fp_exp_mask_of_v<__nv_bfloat16>)
|
||||
&& (__storage & __fp_mant_mask_of_v<__nv_bfloat16>);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E4M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp8_e4m3 __x) noexcept
|
||||
{
|
||||
return (__x.__x & __fp_exp_mant_mask_of_v<__nv_fp8_e4m3>) == __fp_exp_mant_mask_of_v<__nv_fp8_e4m3>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E4M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E5M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp8_e5m2 __x) noexcept
|
||||
{
|
||||
return ((__x.__x & __fp_exp_mask_of_v<__nv_fp8_e5m2>) == __fp_exp_mask_of_v<__nv_fp8_e5m2>)
|
||||
&& (__x.__x & __fp_mant_mask_of_v<__nv_fp8_e5m2>);
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E5M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E8M0()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp8_e8m0 __x) noexcept
|
||||
{
|
||||
return (__x.__x & __fp_exp_mask_of_v<__nv_fp8_e8m0>) == __fp_exp_mask_of_v<__nv_fp8_e8m0>;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E8M0()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E2M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp6_e2m3) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E2M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E3M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp6_e3m2) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E3M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP4_E2M1()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__nv_fp4_e2m1) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP4_E2M1()
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(__float128 __x) noexcept
|
||||
{
|
||||
// __builtin_isnan is not efficient for __float128, prefer __nv_fp128_isnan at run-time
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
NV_IF_TARGET(NV_PROVIDES_SM_100, (return ::__nv_fp128_isnan(__x);)) // preserve NaN behavior even with optimization
|
||||
// flags
|
||||
}
|
||||
# if defined(_CCCL_BUILTIN_ISNAN)
|
||||
return _CCCL_BUILTIN_ISNAN(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISNAN ^^^ / vvv !_CCCL_BUILTIN_ISNAN vvv
|
||||
return __x != __x;
|
||||
# endif // ^^^ !_CCCL_BUILTIN_ISNAN ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnan(_Tp) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ISNAN_H
|
||||
145
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isnormal.h
Normal file
145
cccl_upstream/libcudacxx/include/cuda/std/__cmath/isnormal.h
Normal file
@@ -0,0 +1,145 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ISNORMAL_H
|
||||
#define _CUDA_STD___CMATH_ISNORMAL_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/fpclassify.h>
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isnormal) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISNORMAL(...) __builtin_isnormal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(isnormal)
|
||||
|
||||
// nvcc does not implement __builtin_isnormal
|
||||
#if _CCCL_CUDA_COMPILER(NVCC)
|
||||
# undef _CCCL_BUILTIN_ISNORMAL
|
||||
#endif // _CCCL_CUDA_COMPILER(NVCC)
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISNORMAL)
|
||||
return _CCCL_BUILTIN_ISNORMAL(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISNORMAL ^^^ / vvv !_CCCL_BUILTIN_ISNORMAL vvv
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
#endif // !_CCCL_BUILTIN_ISNORMAL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ISNORMAL)
|
||||
return _CCCL_BUILTIN_ISNORMAL(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ISNORMAL ^^^ / vvv !_CCCL_BUILTIN_ISNORMAL vvv
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
#endif // !_CCCL_BUILTIN_ISNORMAL
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISNORMAL)
|
||||
return _CCCL_BUILTIN_ISNORMAL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISNORMAL ^^^ / vvv !_CCCL_BUILTIN_ISNORMAL vvv
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
# endif // !_CCCL_BUILTIN_ISNORMAL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E4M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp8_e4m3 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E4M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E5M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp8_e5m2 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E5M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP8_E8M0()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp8_e8m0 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP8_E8M0()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E2M3()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp6_e2m3 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E2M3()
|
||||
|
||||
#if _CCCL_HAS_NVFP6_E3M2()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp6_e3m2 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP6_E3M2()
|
||||
|
||||
#if _CCCL_HAS_NVFP4_E2M1()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__nv_fp4_e2m1 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_NVFP4_E2M1()
|
||||
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(__float128 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::fpclassify(__x) == FP_NORMAL;
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_integral_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr bool isnormal(_Tp __x) noexcept
|
||||
{
|
||||
return __x != 0;
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ISNORMAL_H
|
||||
101
cccl_upstream/libcudacxx/include/cuda/std/__cmath/lerp.h
Normal file
101
cccl_upstream/libcudacxx/include/cuda/std/__cmath/lerp.h
Normal file
@@ -0,0 +1,101 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_LERP_H
|
||||
#define _CUDA_STD___CMATH_LERP_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
template <typename _Fp>
|
||||
[[nodiscard]] _CCCL_API constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept
|
||||
{
|
||||
if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
|
||||
{
|
||||
return __t * __b + (1 - __t) * __a;
|
||||
}
|
||||
|
||||
if (__t == 1)
|
||||
{
|
||||
return __b;
|
||||
}
|
||||
const _Fp __x = __a + __t * (__b - __a);
|
||||
if ((__t > 1) == (__b > __a))
|
||||
{
|
||||
return __b < __x ? __x : __b;
|
||||
}
|
||||
else
|
||||
{
|
||||
return __x < __b ? __x : __b;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float lerp(float __a, float __b, float __t) noexcept
|
||||
{
|
||||
return ::cuda::std::__lerp(__a, __b, __t);
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr double lerp(double __a, double __b, double __t) noexcept
|
||||
{
|
||||
return ::cuda::std::__lerp(__a, __b, __t);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double lerp(long double __a, long double __b, long double __t) noexcept
|
||||
{
|
||||
return ::cuda::std::__lerp(__a, __b, __t);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half lerp(__half __a, __half __b, __half __t) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::__lerp(__half2float(__a), __half2float(__b), __half2float(__t)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 lerp(__nv_bfloat16 __a, __nv_bfloat16 __b, __nv_bfloat16 __t) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::__lerp(__bfloat162float(__a), __bfloat162float(__b), __bfloat162float(__t)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, class _A3>
|
||||
[[nodiscard]]
|
||||
_CCCL_API constexpr enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2> && is_arithmetic_v<_A3>,
|
||||
__promote_t<_A1, _A2, _A3>> lerp(_A1 __a, _A2 __b, _A3 __t) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2, _A3>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type> && is_same_v<_A3, __result_type>) );
|
||||
return ::cuda::std::__lerp((__result_type) __a, (__result_type) __b, (__result_type) __t);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_LERP_H
|
||||
537
cccl_upstream/libcudacxx/include/cuda/std/__cmath/logarithms.h
Normal file
537
cccl_upstream/libcudacxx/include/cuda/std/__cmath/logarithms.h
Normal file
@@ -0,0 +1,537 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_LOGARITHMS_H
|
||||
#define _CUDA_STD___CMATH_LOGARITHMS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/abs.h>
|
||||
#include <cuda/std/__cmath/fpclassify.h>
|
||||
#include <cuda/std/__cmath/isinf.h>
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/cstdint>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// log
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_log) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LOGF(...) __builtin_logf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG(...) __builtin_log(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOGL(...) __builtin_logl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_log)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "logf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LOGF
|
||||
# undef _CCCL_BUILTIN_LOG
|
||||
# undef _CCCL_BUILTIN_LOGL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOGF)
|
||||
return _CCCL_BUILTIN_LOGF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOGF ^^^ / vvv !_CCCL_BUILTIN_LOGF vvv
|
||||
return ::logf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOGF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float logf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOGF)
|
||||
return _CCCL_BUILTIN_LOGF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOGF ^^^ / vvv !_CCCL_BUILTIN_LOGF vvv
|
||||
return ::logf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOGF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double log(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG)
|
||||
return _CCCL_BUILTIN_LOG(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG ^^^ / vvv !_CCCL_BUILTIN_LOG vvv
|
||||
return ::log(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double log(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOGL)
|
||||
return _CCCL_BUILTIN_LOGL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOGL ^^^ / vvv !_CCCL_BUILTIN_LOGL vvv
|
||||
return ::logl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOGL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double logl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOGL)
|
||||
return _CCCL_BUILTIN_LOGL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOGL ^^^ / vvv !_CCCL_BUILTIN_LOGL vvv
|
||||
return ::logl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOGL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half log(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_53, (return ::hlog(__x);), ({
|
||||
float __vf = __half2float(__x);
|
||||
__vf = ::cuda::std::logf(__vf);
|
||||
__half_raw __ret_repr = ::__float2half_rn(__vf);
|
||||
|
||||
::cuda::std::uint16_t __repr = ::cuda::std::__fp_get_storage(__x);
|
||||
if (__repr == 7544)
|
||||
{
|
||||
__ret_repr.x -= 1;
|
||||
}
|
||||
|
||||
return __ret_repr;
|
||||
}))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 log(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hlog(__x);), (return __float2bfloat16(::cuda::std::logf(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double log(_Integer __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG)
|
||||
return _CCCL_BUILTIN_LOG((double) __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG ^^^ / vvv !_CCCL_BUILTIN_LOG vvv
|
||||
return ::log((double) __x);
|
||||
#endif // !_CCCL_BUILTIN_LOG
|
||||
}
|
||||
|
||||
// log10
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_log10) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LOG10F(...) __builtin_log10f(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG10(...) __builtin_log10(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG10L(...) __builtin_log10l(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_log10)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "log10f"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LOG10F
|
||||
# undef _CCCL_BUILTIN_LOG10
|
||||
# undef _CCCL_BUILTIN_LOG10L
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log10(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG10F)
|
||||
return _CCCL_BUILTIN_LOG10F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG10F ^^^ / vvv !_CCCL_BUILTIN_LOG10F vvv
|
||||
return ::log10f(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG10F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log10f(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG10F)
|
||||
return _CCCL_BUILTIN_LOG10F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG10F ^^^ / vvv !_CCCL_BUILTIN_LOG10F vvv
|
||||
return ::log10f(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG10F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double log10(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG10)
|
||||
return _CCCL_BUILTIN_LOG10(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG10 ^^^ / vvv !_CCCL_BUILTIN_LOG10 vvv
|
||||
return ::log10(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG10
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double log10(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG10L)
|
||||
return _CCCL_BUILTIN_LOG10L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG10L ^^^ / vvv !_CCCL_BUILTIN_LOG10L vvv
|
||||
return ::log10l(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG10L
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double log10l(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG10L)
|
||||
return _CCCL_BUILTIN_LOG10L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG10L ^^^ / vvv !_CCCL_BUILTIN_LOG10L vvv
|
||||
return ::log10l(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG10L
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half log10(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_PROVIDES_SM_53, (return ::hlog10(__x);), (return __float2half(::cuda::std::log10f(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 log10(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hlog10(__x);), (return __float2bfloat16(::cuda::std::log10f(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double log10(_Integer __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG10)
|
||||
return _CCCL_BUILTIN_LOG10((double) __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG10 ^^^ / vvv !_CCCL_BUILTIN_LOG10 vvv
|
||||
return ::log10((double) __x);
|
||||
#endif // !_CCCL_BUILTIN_LOG10
|
||||
}
|
||||
|
||||
// ilogb
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API inline constexpr int __ilogb_impl(_Tp __x) noexcept
|
||||
{
|
||||
const auto __fp = ::cuda::std::fpclassify(__x);
|
||||
// FP_ILOGB0 and FP_ILOGBNAN may have the same value, but the cases are semantically distinct.
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if (__fp == FP_ZERO)
|
||||
{
|
||||
return FP_ILOGB0;
|
||||
}
|
||||
else if (__fp == FP_NAN)
|
||||
{
|
||||
return FP_ILOGBNAN;
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
else if (__fp == FP_INFINITE)
|
||||
{
|
||||
return numeric_limits<int>::max();
|
||||
}
|
||||
|
||||
constexpr auto __fmt = __fp_format_of_v<_Tp>;
|
||||
const int __exp = ::cuda::std::__fp_get_exp(__x);
|
||||
if (__exp > __fp_exp_max_v<__fmt>)
|
||||
{
|
||||
return numeric_limits<int>::max();
|
||||
}
|
||||
else if (__exp < __fp_exp_min_v<__fmt>)
|
||||
{
|
||||
return numeric_limits<int>::min();
|
||||
}
|
||||
else
|
||||
{
|
||||
return __exp;
|
||||
}
|
||||
}
|
||||
|
||||
_CCCL_TEMPLATE(typename _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API inline constexpr int ilogb(_Tp __x) noexcept
|
||||
{
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return ::cuda::std::__ilogb_impl(static_cast<double>(__x));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::cuda::std::__ilogb_impl(__x);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline constexpr int ilogbf(float __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__ilogb_impl(__x);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline constexpr int ilogbl(long double __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__ilogb_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
// log1p
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_log1p) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LOG1PF(...) __builtin_log1pf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG1P(...) __builtin_log1p(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG1PL(...) __builtin_log1pl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_log1p)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "log1p"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LOG1PF
|
||||
# undef _CCCL_BUILTIN_LOG1P
|
||||
# undef _CCCL_BUILTIN_LOG1PL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log1p(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG1PF)
|
||||
return _CCCL_BUILTIN_LOG1PF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG1PF ^^^ / vvv !_CCCL_BUILTIN_LOG1PF vvv
|
||||
return ::log1pf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG1PF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log1pf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG1PF)
|
||||
return _CCCL_BUILTIN_LOG1PF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG1PF ^^^ / vvv !_CCCL_BUILTIN_LOG1PF vvv
|
||||
return ::log1pf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG1PF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double log1p(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG1P)
|
||||
return _CCCL_BUILTIN_LOG1P(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG1P ^^^ / vvv !_CCCL_BUILTIN_LOG1P vvv
|
||||
return ::log1p(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG1P
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double log1p(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG1PL)
|
||||
return _CCCL_BUILTIN_LOG1PL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG1PL ^^^ / vvv !_CCCL_BUILTIN_LOG1PL vvv
|
||||
return ::log1pl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG1PL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double log1pl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG1PL)
|
||||
return _CCCL_BUILTIN_LOG1PL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG1PL ^^^ / vvv !_CCCL_BUILTIN_LOG1PL vvv
|
||||
return ::log1pl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG1PL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half log1p(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::log1pf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 log1p(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::log1pf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double log1p(_Integer __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG1P)
|
||||
return _CCCL_BUILTIN_LOG1P((double) __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG1P ^^^ / vvv !_CCCL_BUILTIN_LOG1P vvv
|
||||
return ::log1p((double) __x);
|
||||
#endif // !_CCCL_BUILTIN_LOG1P
|
||||
}
|
||||
|
||||
// log2
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_log2) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LOG2F(...) __builtin_log2f(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG2(...) __builtin_log2(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LOG2L(...) __builtin_log2l(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_log1)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "log2f"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LOG2F
|
||||
# undef _CCCL_BUILTIN_LOG2
|
||||
# undef _CCCL_BUILTIN_LOG2L
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log2(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG2F)
|
||||
return _CCCL_BUILTIN_LOG2F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG2F ^^^ / vvv !_CCCL_BUILTIN_LOG2F vvv
|
||||
return ::log2f(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float log2f(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG2F)
|
||||
return _CCCL_BUILTIN_LOG2F(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG2F ^^^ / vvv !_CCCL_BUILTIN_LOG2F vvv
|
||||
return ::log2f(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG2F
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double log2(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG2)
|
||||
return _CCCL_BUILTIN_LOG2(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG2 ^^^ / vvv !_CCCL_BUILTIN_LOG2 vvv
|
||||
return ::log2(__x);
|
||||
#endif // !_CCCL_BUILTIN_LOG2
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double log2(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG2L)
|
||||
return _CCCL_BUILTIN_LOG2L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG2L ^^^ / vvv !_CCCL_BUILTIN_LOG2L vvv
|
||||
return ::log2l(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG2L
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double log2l(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LOG2L)
|
||||
return _CCCL_BUILTIN_LOG2L(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LOG2L ^^^ / vvv !_CCCL_BUILTIN_LOG2L vvv
|
||||
return ::log2l(__x);
|
||||
# endif // !_CCCL_BUILTIN_LOG2L
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half log2(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_PROVIDES_SM_53, (return ::hlog2(__x);), (return __float2half(::cuda::std::log2f(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 log2(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hlog2(__x);), (return __float2bfloat16(::cuda::std::log2f(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double log2(_Integer __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LOG2)
|
||||
return _CCCL_BUILTIN_LOG2((double) __x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LOG2 ^^^ / vvv !_CCCL_BUILTIN_LOG2 vvv
|
||||
return ::log2((double) __x);
|
||||
#endif // !_CCCL_BUILTIN_LOG2
|
||||
}
|
||||
|
||||
// logb
|
||||
|
||||
template <class _Tp>
|
||||
[[nodiscard]] _CCCL_API inline constexpr _Tp __logb_impl(_Tp __x) noexcept
|
||||
{
|
||||
const auto __fp = ::cuda::std::fpclassify(__x);
|
||||
if (__fp == FP_ZERO)
|
||||
{
|
||||
return ::cuda::std::__fp_neg<_Tp>(::cuda::std::__fp_inf<_Tp>());
|
||||
}
|
||||
else if (__fp == FP_NAN)
|
||||
{
|
||||
return ::cuda::std::__fp_nan<_Tp>();
|
||||
}
|
||||
else if (__fp == FP_INFINITE)
|
||||
{
|
||||
return ::cuda::std::__fp_inf<_Tp>();
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
return static_cast<_Tp>(::cuda::std::__fp_get_exp(__x));
|
||||
#else // ^^^ _CCCL_HAS_CONSTEXPR_BIT_CAST() ^^^ / vvv !_CCCL_HAS_CONSTEXPR_BIT_CAST() vvv
|
||||
// We need to go through the slow emulation for old GCC
|
||||
if constexpr (__fp_is_native_type_v<_Tp>)
|
||||
{
|
||||
__x = ::cuda::std::fabs(__x);
|
||||
unsigned long long __exp = 0;
|
||||
while (__x >= _Tp(numeric_limits<_Tp>::radix))
|
||||
{
|
||||
__x /= numeric_limits<_Tp>::radix;
|
||||
__exp += 1;
|
||||
}
|
||||
return static_cast<_Tp>(__exp);
|
||||
}
|
||||
else
|
||||
{
|
||||
return static_cast<_Tp>(::cuda::std::__fp_get_exp(__x));
|
||||
}
|
||||
#endif // !_CCCL_HAS_CONSTEXPR_BIT_CAST()
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline constexpr float logbf(float __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__logb_impl(__x);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline constexpr long double logbl(long double __x) noexcept
|
||||
{
|
||||
return ::cuda::std::__logb_impl(__x);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
template <class _Tp, enable_if_t<__is_extended_arithmetic_v<_Tp>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline constexpr conditional_t<is_integral_v<_Tp>, double, _Tp> logb(_Tp __x) noexcept
|
||||
{
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return ::cuda::std::__logb_impl(static_cast<double>(__x));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::cuda::std::__logb_impl(__x);
|
||||
}
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_LOGARITHMS_H
|
||||
292
cccl_upstream/libcudacxx/include/cuda/std/__cmath/min_max.h
Normal file
292
cccl_upstream/libcudacxx/include/cuda/std/__cmath/min_max.h
Normal file
@@ -0,0 +1,292 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_MIN_MAX_H
|
||||
#define _CUDA_STD___CMATH_MIN_MAX_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/__type_traits/is_floating_point.h>
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__type_traits/conditional.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* fmax
|
||||
**********************************************************************************************************************/
|
||||
|
||||
// We do explicitly also enable GCC here, because that makes the condition below simpler
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fmax) || _CCCL_COMPILER(GCC)
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_floating_point_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API _Tp __with_builtin_fmax(_Tp __x, _Tp __y) noexcept
|
||||
{
|
||||
if constexpr (is_same_v<_Tp, float>)
|
||||
{
|
||||
return __builtin_fmaxf(__x, __y);
|
||||
}
|
||||
else if constexpr (is_same_v<_Tp, double>)
|
||||
{
|
||||
return __builtin_fmax(__x, __y);
|
||||
}
|
||||
# if _CCCL_HAS_LONG_DOUBLE()
|
||||
else if constexpr (is_same_v<_Tp, long double>)
|
||||
{
|
||||
return __builtin_fmaxl(__x, __y);
|
||||
}
|
||||
# endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
}
|
||||
|
||||
# define _CCCL_USE_BUILTIN_FMAX() 1
|
||||
#else //
|
||||
# define _CCCL_USE_BUILTIN_FMAX() 0
|
||||
#endif // _CCCL_BUILTIN_FABSF
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr conditional_t<is_integral_v<_Tp>, double, _Tp> fmax(_Tp __x, _Tp __y) noexcept
|
||||
{
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
// The half and bfloat16 branches can become identical under some CUDA Toolkit versions.
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (is_same_v<_Tp, ::__half>)
|
||||
{
|
||||
# if _CCCL_CTK_AT_LEAST(12, 2)
|
||||
return ::__hmax(__x, __y);
|
||||
# else // ^^^ _CCCL_CTK_AT_LEAST(12, 2) ^^^ / vvv !_CCCL_CTK_AT_LEAST(12, 2) vvv
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE,
|
||||
(return ::__hmax(__x, __y);),
|
||||
(return ::__float2half(::cuda::std::fmax(::__half2float(__x), ::__half2float(__y)));))
|
||||
# endif // !_CCCL_CTK_AT_LEAST(12, 2)
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
else
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
if constexpr (is_same_v<_Tp, ::__nv_bfloat16>)
|
||||
{
|
||||
# if _CCCL_CTK_AT_LEAST(12, 2)
|
||||
return ::__hmax(__x, __y);
|
||||
# else // ^^^ _CCCL_CTK_AT_LEAST(12, 2) ^^^ / vvv !_CCCL_CTK_AT_LEAST(12, 2) vvv
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,
|
||||
(return ::__hmax(__x, __y);),
|
||||
(return ::__float2bfloat16(::cuda::std::fmax(::__bfloat162float(__x), ::__bfloat162float(__y)));))
|
||||
# endif // !_CCCL_CTK_AT_LEAST(12, 2)
|
||||
}
|
||||
else
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return static_cast<double>(__x < __y ? __y : __x);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
if constexpr (is_same_v<_Tp, __float128>)
|
||||
{
|
||||
NV_IF_TARGET(NV_PROVIDES_SM_100, (return ::__nv_fp128_fmax(__x, __y);))
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
#if _CCCL_USE_BUILTIN_FMAX()
|
||||
if constexpr (is_floating_point_v<_Tp>)
|
||||
{
|
||||
// GCC builtins do not treat NaN properly
|
||||
# if _CCCL_COMPILER(GCC)
|
||||
NV_IF_TARGET(NV_IS_DEVICE, (return ::cuda::std::__with_builtin_fmax(__x, __y);))
|
||||
# else // ^^^ _CCCL_COMPILER(GCC) ^^^ / vvv !_CCCL_COMPILER(GCC)
|
||||
return ::cuda::std::__with_builtin_fmax(__x, __y);
|
||||
# endif // !_CCCL_COMPILER(GCC)
|
||||
}
|
||||
#endif // _CCCL_USE_BUILTIN_FMAX
|
||||
}
|
||||
if (::cuda::std::isnan(__x))
|
||||
{
|
||||
return __y;
|
||||
}
|
||||
else if (::cuda::std::isnan(__y))
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return __x < __y ? __y : __x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float fmaxf(float __x, float __y) noexcept
|
||||
{
|
||||
return ::cuda::std::fmax(__x, __y);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double fmaxl(long double __x, long double __y) noexcept
|
||||
{
|
||||
return ::cuda::std::fmax(__x, __y);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp, class _Up)
|
||||
_CCCL_REQUIRES(::cuda::is_floating_point_v<_Tp> _CCCL_AND ::cuda::is_floating_point_v<_Up>)
|
||||
[[nodiscard]] _CCCL_API constexpr auto fmax(_Tp __x, _Up __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_Tp, _Up>;
|
||||
static_assert(!(is_same_v<_Tp, __result_type> && is_same_v<_Up, __result_type>) );
|
||||
return ::cuda::std::fmax(static_cast<__result_type>(__x), static_cast<__result_type>(__y));
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* fmin
|
||||
**********************************************************************************************************************/
|
||||
|
||||
// We do explicitly also enable GCC here, because that makes the condition below simpler
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fmin) || _CCCL_COMPILER(GCC)
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(is_floating_point_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API _Tp __with_builtin_fmin(_Tp __x, _Tp __y) noexcept
|
||||
{
|
||||
if constexpr (is_same_v<_Tp, float>)
|
||||
{
|
||||
return __builtin_fminf(__x, __y);
|
||||
}
|
||||
else if constexpr (is_same_v<_Tp, double>)
|
||||
{
|
||||
return __builtin_fmin(__x, __y);
|
||||
}
|
||||
# if _CCCL_HAS_LONG_DOUBLE()
|
||||
else if constexpr (is_same_v<_Tp, long double>)
|
||||
{
|
||||
return __builtin_fminl(__x, __y);
|
||||
}
|
||||
# endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
}
|
||||
|
||||
# define _CCCL_USE_BUILTIN_FMIN() 1
|
||||
#else //
|
||||
# define _CCCL_USE_BUILTIN_FMIN() 0
|
||||
#endif // _CCCL_BUILTIN_FABSF
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr conditional_t<is_integral_v<_Tp>, double, _Tp> fmin(_Tp __x, _Tp __y) noexcept
|
||||
{
|
||||
#if _CCCL_HAS_NVFP16()
|
||||
// The half and bfloat16 branches can become identical under some CUDA Toolkit versions.
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (is_same_v<_Tp, ::__half>)
|
||||
{
|
||||
# if _CCCL_CTK_AT_LEAST(12, 2)
|
||||
return ::__hmin(__x, __y);
|
||||
# else // ^^^ _CCCL_CTK_AT_LEAST(12, 2) ^^^ / vvv !_CCCL_CTK_AT_LEAST(12, 2) vvv
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE,
|
||||
(return ::__hmin(__x, __y);),
|
||||
(return ::__float2half(::cuda::std::fmin(::__half2float(__x), ::__half2float(__y)));))
|
||||
# endif // !_CCCL_CTK_AT_LEAST(12, 2)
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
else
|
||||
#endif // _CCCL_HAS_NVFP16()
|
||||
#if _CCCL_HAS_NVBF16()
|
||||
if constexpr (is_same_v<_Tp, ::__nv_bfloat16>)
|
||||
{
|
||||
# if _CCCL_CTK_AT_LEAST(12, 2)
|
||||
return ::__hmin(__x, __y);
|
||||
# else // ^^^ _CCCL_CTK_AT_LEAST(12, 2) ^^^ / vvv !_CCCL_CTK_AT_LEAST(12, 2) vvv
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_80,
|
||||
(return ::__hmin(__x, __y);),
|
||||
(return ::__float2bfloat16(::cuda::std::fmin(::__bfloat162float(__x), ::__bfloat162float(__y)));))
|
||||
# endif // !_CCCL_CTK_AT_LEAST(12, 2)
|
||||
}
|
||||
else
|
||||
#endif // _CCCL_HAS_NVBF16()
|
||||
if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return static_cast<double>(__y < __x ? __y : __x);
|
||||
}
|
||||
else
|
||||
{
|
||||
_CCCL_IF_NOT_CONSTEVAL_DEFAULT
|
||||
{
|
||||
#if _CCCL_HAS_FLOAT128()
|
||||
if constexpr (is_same_v<_Tp, __float128>)
|
||||
{
|
||||
NV_IF_TARGET(NV_PROVIDES_SM_100, (return ::__nv_fp128_fmin(__x, __y);))
|
||||
}
|
||||
#endif // _CCCL_HAS_FLOAT128()
|
||||
#if _CCCL_USE_BUILTIN_FMAX()
|
||||
if constexpr (is_floating_point_v<_Tp>)
|
||||
{
|
||||
// GCC builtins do not treat NaN properly
|
||||
# if _CCCL_COMPILER(GCC)
|
||||
NV_IF_TARGET(NV_IS_DEVICE, (return ::cuda::std::__with_builtin_fmin(__x, __y);))
|
||||
# else // ^^^ _CCCL_COMPILER(GCC) ^^^ / vvv !_CCCL_COMPILER(GCC)
|
||||
return ::cuda::std::__with_builtin_fmin(__x, __y);
|
||||
# endif // !_CCCL_COMPILER(GCC)
|
||||
}
|
||||
#endif // _CCCL_USE_BUILTIN_FMAX
|
||||
}
|
||||
if (::cuda::std::isnan(__x))
|
||||
{
|
||||
return __y;
|
||||
}
|
||||
else if (::cuda::std::isnan(__y))
|
||||
{
|
||||
return __x;
|
||||
}
|
||||
return __y < __x ? __y : __x;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float fminf(float __x, float __y) noexcept
|
||||
{
|
||||
return ::cuda::std::fmin(__x, __y);
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double fminl(long double __x, long double __y) noexcept
|
||||
{
|
||||
return ::cuda::std::fmin(__x, __y);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp, class _Up)
|
||||
_CCCL_REQUIRES(::cuda::is_floating_point_v<_Tp> _CCCL_AND ::cuda::is_floating_point_v<_Up>)
|
||||
[[nodiscard]] _CCCL_API constexpr auto fmin(_Tp __x, _Up __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_Tp, _Up>;
|
||||
static_assert(!(is_same_v<_Tp, __result_type> && is_same_v<_Up, __result_type>) );
|
||||
return ::cuda::std::fmin(static_cast<__result_type>(__x), static_cast<__result_type>(__y));
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_MIN_MAX_H
|
||||
208
cccl_upstream/libcudacxx/include/cuda/std/__cmath/modulo.h
Normal file
208
cccl_upstream/libcudacxx/include/cuda/std/__cmath/modulo.h
Normal file
@@ -0,0 +1,208 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_MODULO_H
|
||||
#define _CUDA_STD___CMATH_MODULO_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/copysign.h>
|
||||
#include <cuda/std/__cmath/rounding_functions.h>
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// fmod
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_fmod) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FMODF(...) __builtin_fmodf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FMOD(...) __builtin_fmod(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FMODL(...) __builtin_fmodl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_fmod)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "modf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_FMODF
|
||||
# undef _CCCL_BUILTIN_FMOD
|
||||
# undef _CCCL_BUILTIN_FMODL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float fmod(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMODF)
|
||||
return _CCCL_BUILTIN_FMODF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMODF ^^^ / vvv !_CCCL_BUILTIN_FMODF vvv
|
||||
return ::fmodf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMODF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float fmodf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMODF)
|
||||
return _CCCL_BUILTIN_FMODF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMODF ^^^ / vvv !_CCCL_BUILTIN_FMODF vvv
|
||||
return ::fmodf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMODF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double fmod(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FMOD)
|
||||
return _CCCL_BUILTIN_FMOD(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_FMOD ^^^ / vvv !_CCCL_BUILTIN_FMOD vvv
|
||||
return ::fmod(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_FMOD ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double fmod(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FMODL)
|
||||
return _CCCL_BUILTIN_FMODL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_FMODL ^^^ / vvv !_CCCL_BUILTIN_FMODL vvv
|
||||
return ::fmodl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FMODL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double fmodl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FMODL)
|
||||
return _CCCL_BUILTIN_FMODL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_FMODL ^^^ / vvv !_CCCL_BUILTIN_FMODL vvv
|
||||
return ::fmodl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_FMODL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half fmod(__half __x, __half __y) noexcept
|
||||
{
|
||||
return ::__float2half(::cuda::std::fmod(::__half2float(__x), ::__half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 fmod(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return ::__float2bfloat16(::cuda::std::fmod(::__bfloat162float(__x), ::__bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline __promote_t<_A1, _A2> fmod(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::fmod((__result_type) __x, (__result_type) __y);
|
||||
}
|
||||
|
||||
// modf
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_modf) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_MODFF(...) __builtin_modff(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_MODF(...) __builtin_modf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_MODFL(...) __builtin_modfl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_modf)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "modf"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_MODFF
|
||||
# undef _CCCL_BUILTIN_MODF
|
||||
# undef _CCCL_BUILTIN_MODFL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float modf(float __x, float* __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_MODFF)
|
||||
return _CCCL_BUILTIN_MODFF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_MODFF ^^^ / vvv !_CCCL_BUILTIN_MODFF vvv
|
||||
return ::modff(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_MODFF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float modff(float __x, float* __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_MODFF)
|
||||
return _CCCL_BUILTIN_MODFF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_MODFF ^^^ / vvv !_CCCL_BUILTIN_MODFF vvv
|
||||
return ::modff(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_MODFF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double modf(double __x, double* __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_MODF)
|
||||
return _CCCL_BUILTIN_MODF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_MODF ^^^ / vvv !_CCCL_BUILTIN_MODF vvv
|
||||
return ::modf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_MODF ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double modf(long double __x, long double* __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_MODFL)
|
||||
return _CCCL_BUILTIN_MODFL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_MODFL ^^^ / vvv !_CCCL_BUILTIN_MODFL vvv
|
||||
return ::modfl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_MODFL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double modfl(long double __x, long double* __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_MODFL)
|
||||
return _CCCL_BUILTIN_MODFL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_MODFL ^^^ / vvv !_CCCL_BUILTIN_MODFL vvv
|
||||
return ::modfl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_MODFL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half modf(__half __x, __half* __y) noexcept
|
||||
{
|
||||
const __half __integral_part = ::cuda::std::trunc(__x);
|
||||
*__y = __integral_part;
|
||||
return ::__heq(__integral_part, __x)
|
||||
? ::cuda::std::copysign(::__float2half(0.0f), __x)
|
||||
: ::__hsub(__x, __integral_part);
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 modf(__nv_bfloat16 __x, __nv_bfloat16* __y) noexcept
|
||||
{
|
||||
const __nv_bfloat16 __integral_part = ::cuda::std::trunc(__x);
|
||||
*__y = __integral_part;
|
||||
return ::__heq(__integral_part, __x)
|
||||
? ::cuda::std::copysign(::__float2bfloat16(0.0f), __x)
|
||||
: ::__hsub(__x, __integral_part);
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_MODULO_H
|
||||
54
cccl_upstream/libcudacxx/include/cuda/std/__cmath/nan.h
Normal file
54
cccl_upstream/libcudacxx/include/cuda/std/__cmath/nan.h
Normal file
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_NAN_H
|
||||
#define _CUDA_STD___CMATH_NAN_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// nan
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr float nanf(const char*) noexcept
|
||||
{
|
||||
return ::cuda::std::numeric_limits<float>::quiet_NaN();
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API constexpr double nan(const char*) noexcept
|
||||
{
|
||||
return ::cuda::std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API constexpr long double nanl(const char*) noexcept
|
||||
{
|
||||
return ::cuda::std::numeric_limits<long double>::quiet_NaN();
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_NAN_H
|
||||
207
cccl_upstream/libcudacxx/include/cuda/std/__cmath/remainder.h
Normal file
207
cccl_upstream/libcudacxx/include/cuda/std/__cmath/remainder.h
Normal file
@@ -0,0 +1,207 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_REMAINDER_H
|
||||
#define _CUDA_STD___CMATH_REMAINDER_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// remainder
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_remainder) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_REMAINDERF(...) __builtin_remainderf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_REMAINDER(...) __builtin_remainder(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_REMAINDERL(...) __builtin_remainderl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_remainder)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "remainder"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_REMAINDERF
|
||||
# undef _CCCL_BUILTIN_REMAINDER
|
||||
# undef _CCCL_BUILTIN_REMAINDERFL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float remainder(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMAINDERF)
|
||||
return _CCCL_BUILTIN_REMAINDERF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMAINDERF ^^^ / vvv !_CCCL_BUILTIN_REMAINDERF vvv
|
||||
return ::remainderf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMAINDERF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float remainderf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMAINDERF)
|
||||
return _CCCL_BUILTIN_REMAINDERF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMAINDERF ^^^ / vvv !_CCCL_BUILTIN_REMAINDERF vvv
|
||||
return ::remainderf(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMAINDERF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double remainder(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMAINDER)
|
||||
return _CCCL_BUILTIN_REMAINDER(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMAINDER ^^^ / vvv !_CCCL_BUILTIN_REMAINDER vvv
|
||||
return ::remainder(__x, __y);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMAINDER ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double remainder(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_REMAINDERL)
|
||||
return _CCCL_BUILTIN_REMAINDERL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_REMAINDERL ^^^ / vvv !_CCCL_BUILTIN_REMAINDERL vvv
|
||||
return ::remainderl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_REMAINDERL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double remainderl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_REMAINDERL)
|
||||
return _CCCL_BUILTIN_REMAINDERL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_REMAINDERL ^^^ / vvv !_CCCL_BUILTIN_REMAINDERL vvv
|
||||
return ::remainderl(__x, __y);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_REMAINDERL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half remainder(__half __x, __half __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::remainder(__half2float(__x), __half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 remainder(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::remainder(__bfloat162float(__x), __bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline __promote_t<_A1, _A2> remainder(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::remainder((__result_type) __x, (__result_type) __y);
|
||||
}
|
||||
|
||||
// remquo
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_remquo) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_REMQUOF(...) __builtin_remquof(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_REMQUO(...) __builtin_remquo(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_REMQUOL(...) __builtin_remquol(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_remquo)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "remquo"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_REMQUOF
|
||||
# undef _CCCL_BUILTIN_REMQUO
|
||||
# undef _CCCL_BUILTIN_REMQUOL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float remquo(float __x, float __y, int* __quotient) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMQUOF)
|
||||
return _CCCL_BUILTIN_REMQUOF(__x, __y, __quotient);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMQUOF ^^^ / vvv !_CCCL_BUILTIN_REMQUOF vvv
|
||||
return ::remquof(__x, __y, __quotient);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMQUOF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float remquof(float __x, float __y, int* __quotient) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMQUOF)
|
||||
return _CCCL_BUILTIN_REMQUOF(__x, __y, __quotient);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMQUOF ^^^ / vvv !_CCCL_BUILTIN_REMQUOF vvv
|
||||
return ::remquof(__x, __y, __quotient);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMQUOF ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double remquo(double __x, double __y, int* __quotient) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_REMQUO)
|
||||
return _CCCL_BUILTIN_REMQUO(__x, __y, __quotient);
|
||||
#else // ^^^ _CCCL_BUILTIN_REMQUO ^^^ / vvv !_CCCL_BUILTIN_REMQUO vvv
|
||||
return ::remquo(__x, __y, __quotient);
|
||||
#endif // ^^^ !_CCCL_BUILTIN_REMQUO ^^^
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double remquo(long double __x, long double __y, int* __quotient) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_REMQUOL)
|
||||
return _CCCL_BUILTIN_REMQUOL(__x, __y, __quotient);
|
||||
# else // ^^^ _CCCL_BUILTIN_REMQUOL ^^^ / vvv !_CCCL_BUILTIN_REMQUOL vvv
|
||||
return ::remquol(__x, __y, __quotient);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_REMQUOL ^^^
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double remquol(long double __x, long double __y, int* __quotient) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_REMQUOL)
|
||||
return _CCCL_BUILTIN_REMQUOL(__x, __y, __quotient);
|
||||
# else // ^^^ _CCCL_BUILTIN_REMQUOL ^^^ / vvv !_CCCL_BUILTIN_REMQUOL vvv
|
||||
return ::remquol(__x, __y, __quotient);
|
||||
# endif // ^^^ !_CCCL_BUILTIN_REMQUOL ^^^
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half remquo(__half __x, __half __y, int* __quotient) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::remquo(__half2float(__x), __half2float(__y), __quotient));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 remquo(__nv_bfloat16 __x, __nv_bfloat16 __y, int* __quotient) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::remquo(__bfloat162float(__x), __bfloat162float(__y), __quotient));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline __promote_t<_A1, _A2> remquo(_A1 __x, _A2 __y, int* __quotient) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::remquo((__result_type) __x, (__result_type) __y, __quotient);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_MODULO_H
|
||||
195
cccl_upstream/libcudacxx/include/cuda/std/__cmath/roots.h
Normal file
195
cccl_upstream/libcudacxx/include/cuda/std/__cmath/roots.h
Normal file
@@ -0,0 +1,195 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ROOTS_H
|
||||
#define _CUDA_STD___CMATH_ROOTS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// sqrt
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_sqrt) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_SQRTF(...) __builtin_sqrtf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SQRT(...) __builtin_sqrt(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SQRTL(...) __builtin_sqrtl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_sqrt)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float sqrt(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SQRTF)
|
||||
return _CCCL_BUILTIN_SQRTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SQRTF ^^^ // vvv !_CCCL_BUILTIN_SQRTF vvv
|
||||
return ::sqrtf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SQRTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float sqrtf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SQRTF)
|
||||
return _CCCL_BUILTIN_SQRTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SQRTF ^^^ // vvv !_CCCL_BUILTIN_SQRTF vvv
|
||||
return ::sqrtf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SQRTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double sqrt(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SQRT)
|
||||
return _CCCL_BUILTIN_SQRT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SQRT ^^^ // vvv !_CCCL_BUILTIN_SQRT vvv
|
||||
return ::sqrt(__x);
|
||||
#endif // !_CCCL_BUILTIN_SQRT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double sqrt(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SQRTL)
|
||||
return _CCCL_BUILTIN_SQRTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SQRTL ^^^ // vvv !_CCCL_BUILTIN_SQRTL vvv
|
||||
return ::sqrtl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SQRTL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double sqrtl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SQRTL)
|
||||
return _CCCL_BUILTIN_SQRTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SQRTL ^^^ // vvv !_CCCL_BUILTIN_SQRTL vvv
|
||||
return ::sqrtl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SQRTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half sqrt(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::hsqrt(__x);), (return __float2half(::cuda::std::sqrt(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 sqrt(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hsqrt(__x);), (return __float2bfloat16(::cuda::std::sqrt(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double sqrt(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::sqrt((double) __x);
|
||||
}
|
||||
|
||||
// cbrt
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_cbrt) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_CBRTF(...) __builtin_cbrtf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_CBRT(...) __builtin_cbrt(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_CBRTL(...) __builtin_cbrtl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_cbrt)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "cbrt"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_CBRTF
|
||||
# undef _CCCL_BUILTIN_CBRT
|
||||
# undef _CCCL_BUILTIN_CBRTL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float cbrt(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CBRTF)
|
||||
return _CCCL_BUILTIN_CBRTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CBRTF ^^^ // vvv !_CCCL_BUILTIN_CBRTF vvv
|
||||
return ::cbrtf(__x);
|
||||
#endif // !_CCCL_BUILTIN_CBRTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float cbrtf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CBRTF)
|
||||
return _CCCL_BUILTIN_CBRTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CBRTF ^^^ // vvv !_CCCL_BUILTIN_CBRTF vvv
|
||||
return ::cbrtf(__x);
|
||||
#endif // !_CCCL_BUILTIN_CBRTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double cbrt(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CBRT)
|
||||
return _CCCL_BUILTIN_CBRT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CBRT ^^^ // vvv !_CCCL_BUILTIN_CBRT vvv
|
||||
return ::cbrt(__x);
|
||||
#endif // !_CCCL_BUILTIN_CBRT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double cbrt(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_CBRTL)
|
||||
return _CCCL_BUILTIN_CBRTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_CBRTL ^^^ // vvv !_CCCL_BUILTIN_CBRTL vvv
|
||||
return ::cbrtl(__x);
|
||||
# endif // !_CCCL_BUILTIN_CBRTL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double cbrtl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_CBRTL)
|
||||
return _CCCL_BUILTIN_CBRTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_CBRTL ^^^ // vvv !_CCCL_BUILTIN_CBRTL vvv
|
||||
return ::cbrtl(__x);
|
||||
# endif // !_CCCL_BUILTIN_CBRTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half cbrt(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::cbrt(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 cbrt(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::cbrt(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double cbrt(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::cbrt((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ROOTS_H
|
||||
@@ -0,0 +1,980 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_ROUNDING_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_ROUNDING_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/is_same.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// ceil
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_ceil) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_CEILF(...) __builtin_ceilf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_CEIL(...) __builtin_ceil(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_CEILL(...) __builtin_ceill(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_ceil)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float ceil(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CEILF)
|
||||
return _CCCL_BUILTIN_CEILF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CEILF ^^^ // vvv !_CCCL_BUILTIN_CEILF vvv
|
||||
return ::ceilf(__x);
|
||||
#endif // !_CCCL_BUILTIN_CEILF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float ceilf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CEILF)
|
||||
return _CCCL_BUILTIN_CEILF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CEILF ^^^ // vvv !_CCCL_BUILTIN_CEILF vvv
|
||||
return ::ceilf(__x);
|
||||
#endif // !_CCCL_BUILTIN_CEILF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double ceil(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_CEIL)
|
||||
return _CCCL_BUILTIN_CEIL(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_CEIL ^^^ // vvv !_CCCL_BUILTIN_CEIL vvv
|
||||
return ::ceil(__x);
|
||||
#endif // !_CCCL_BUILTIN_CEIL
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double ceil(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_CEILL)
|
||||
return _CCCL_BUILTIN_CEILL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_CEILL ^^^ // vvv !_CCCL_BUILTIN_CEILL vvv
|
||||
return ::ceill(__x);
|
||||
# endif // !_CCCL_BUILTIN_CEILL
|
||||
}
|
||||
[[nodiscard]] _CCCL_API inline long double ceill(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_CEILL)
|
||||
return _CCCL_BUILTIN_CEILL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_CEILL ^^^ // vvv !_CCCL_BUILTIN_CEILL vvv
|
||||
return ::ceill(__x);
|
||||
# endif // !_CCCL_BUILTIN_CEILL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half ceil(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::hceil(__x);), (return __float2half(::cuda::std::ceil(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 ceil(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hceil(__x);), (return __float2bfloat16(::cuda::std::ceil(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double ceil(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::ceil((double) __x);
|
||||
}
|
||||
|
||||
// floor
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_floor) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_FLOORF(...) __builtin_floorf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FLOOR(...) __builtin_floor(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_FLOORL(...) __builtin_floorl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_floor)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float floor(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FLOORF)
|
||||
return _CCCL_BUILTIN_FLOORF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_FLOORF ^^^ // vvv !_CCCL_BUILTIN_FLOORF vvv
|
||||
return ::floorf(__x);
|
||||
#endif // !_CCCL_BUILTIN_FLOORF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float floorf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FLOORF)
|
||||
return _CCCL_BUILTIN_FLOORF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_FLOORF ^^^ // vvv !_CCCL_BUILTIN_FLOORF vvv
|
||||
return ::floorf(__x);
|
||||
#endif // !_CCCL_BUILTIN_FLOORF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double floor(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_FLOOR)
|
||||
return _CCCL_BUILTIN_FLOOR(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_FLOOR ^^^ // vvv !_CCCL_BUILTIN_FLOOR vvv
|
||||
return ::floor(__x);
|
||||
#endif // !_CCCL_BUILTIN_FLOOR
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double floor(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FLOORL)
|
||||
return _CCCL_BUILTIN_FLOORL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_FLOORL ^^^ // vvv !_CCCL_BUILTIN_FLOORL vvv
|
||||
return ::floorl(__x);
|
||||
# endif // !_CCCL_BUILTIN_FLOORL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double floorl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_FLOORL)
|
||||
return _CCCL_BUILTIN_FLOORL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_FLOORL ^^^ // vvv !_CCCL_BUILTIN_FLOORL vvv
|
||||
return ::floorl(__x);
|
||||
# endif // !_CCCL_BUILTIN_FLOORL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half floor(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::hfloor(__x);), (return __float2half(::cuda::std::floor(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 floor(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hfloor(__x);), (return __float2bfloat16(::cuda::std::floor(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double floor(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::floor((double) __x);
|
||||
}
|
||||
|
||||
// llrint
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_llrint) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LLRINTF(...) __builtin_llrintf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LLRINT(...) __builtin_llrint(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LLRINTL(...) __builtin_llrintl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_llrint)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "llrint"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LLRINTF
|
||||
# undef _CCCL_BUILTIN_LLRINT
|
||||
# undef _CCCL_BUILTIN_LLRINTL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
_CCCL_API inline long long llrint(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLRINTF)
|
||||
return _CCCL_BUILTIN_LLRINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLRINTF ^^^ // vvv !_CCCL_BUILTIN_LLRINTF vvv
|
||||
return ::llrintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLRINTF
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llrintf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLRINTF)
|
||||
return _CCCL_BUILTIN_LLRINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLRINTF ^^^ // vvv !_CCCL_BUILTIN_LLRINTF vvv
|
||||
return ::llrintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLRINTF
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llrint(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLRINT)
|
||||
return _CCCL_BUILTIN_LLRINT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLRINT ^^^ // vvv !_CCCL_BUILTIN_LLRINT vvv
|
||||
return ::llrint(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLRINT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline long long llrint(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LLRINTL)
|
||||
return _CCCL_BUILTIN_LLRINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LLRINTL ^^^ // vvv !_CCCL_BUILTIN_LLRINTL vvv
|
||||
return ::llrintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LLRINTL
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llrintl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LLRINTL)
|
||||
return _CCCL_BUILTIN_LLRINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LLRINTL ^^^ // vvv !_CCCL_BUILTIN_LLRINTL vvv
|
||||
return ::llrintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LLRINTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline long long llrint(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llrintf(__half2float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline long long llrint(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llrintf(__bfloat162float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
_CCCL_API inline long long llrint(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llrint((double) __x);
|
||||
}
|
||||
|
||||
// llround
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_llround) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LLROUNDF(...) __builtin_llroundf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LLROUND(...) __builtin_llround(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LLROUNDL(...) __builtin_llroundl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_llround)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "llround"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LLROUNDF
|
||||
# undef _CCCL_BUILTIN_LLROUND
|
||||
# undef _CCCL_BUILTIN_LLROUNDL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
_CCCL_API inline long long llround(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLROUNDF)
|
||||
return _CCCL_BUILTIN_LLROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLROUNDF ^^^ // vvv !_CCCL_BUILTIN_LLROUNDF vvv
|
||||
return ::llroundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLROUNDF
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llroundf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLROUNDF)
|
||||
return _CCCL_BUILTIN_LLROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLROUNDF ^^^ // vvv !_CCCL_BUILTIN_LLROUNDF vvv
|
||||
return ::llroundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLROUNDF
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llround(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LLROUND)
|
||||
return _CCCL_BUILTIN_LLROUND(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LLROUND ^^^ // vvv !_CCCL_BUILTIN_LLROUND vvv
|
||||
return ::llround(__x);
|
||||
#endif // !_CCCL_BUILTIN_LLROUND
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline long long llround(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LLROUNDL)
|
||||
return _CCCL_BUILTIN_LLROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LLROUNDL ^^^ // vvv !_CCCL_BUILTIN_LLROUNDL vvv
|
||||
return ::llroundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LLROUNDL
|
||||
}
|
||||
|
||||
_CCCL_API inline long long llroundl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LLROUNDL)
|
||||
return _CCCL_BUILTIN_LLROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LLROUNDL ^^^ // vvv !_CCCL_BUILTIN_LLROUNDL vvv
|
||||
return ::llroundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LLROUNDL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline long long llround(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llroundf(__half2float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline long long llround(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llroundf(__bfloat162float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
_CCCL_API inline long long llround(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::llround((double) __x);
|
||||
}
|
||||
|
||||
// lrint
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_lrint) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LRINTF(...) __builtin_lrintf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LRINT(...) __builtin_lrint(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LRINTL(...) __builtin_lrintl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_lrint)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "lrint"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LRINTF
|
||||
# undef _CCCL_BUILTIN_LRINT
|
||||
# undef _CCCL_BUILTIN_LRINTL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
_CCCL_API inline long lrint(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LRINTF)
|
||||
return _CCCL_BUILTIN_LRINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LRINTF ^^^ // vvv !_CCCL_BUILTIN_LRINTF vvv
|
||||
return ::lrintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LRINTF
|
||||
}
|
||||
|
||||
_CCCL_API inline long lrintf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LRINTF)
|
||||
return _CCCL_BUILTIN_LRINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LRINTF ^^^ // vvv !_CCCL_BUILTIN_LRINTF vvv
|
||||
return ::lrintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LRINTF
|
||||
}
|
||||
|
||||
_CCCL_API inline long lrint(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LRINT)
|
||||
return _CCCL_BUILTIN_LRINT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LRINT ^^^ // vvv !_CCCL_BUILTIN_LRINT vvv
|
||||
return ::lrint(__x);
|
||||
#endif // !_CCCL_BUILTIN_LRINT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline long lrint(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LRINTL)
|
||||
return _CCCL_BUILTIN_LRINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LRINTL ^^^ // vvv !_CCCL_BUILTIN_LRINTL vvv
|
||||
return ::lrintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LRINTL
|
||||
}
|
||||
|
||||
_CCCL_API inline long lrintl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LRINTL)
|
||||
return _CCCL_BUILTIN_LRINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LRINTL ^^^ // vvv !_CCCL_BUILTIN_LRINTL vvv
|
||||
return ::lrintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LRINTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline long lrint(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lrintf(__half2float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline long lrint(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lrintf(__bfloat162float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
_CCCL_API inline long lrint(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lrint((double) __x);
|
||||
}
|
||||
|
||||
// lround
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_lround) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_LROUNDF(...) __builtin_lroundf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LROUND(...) __builtin_lround(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_LROUNDL(...) __builtin_lroundl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_lround)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "lround"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_LROUNDF
|
||||
# undef _CCCL_BUILTIN_LROUND
|
||||
# undef _CCCL_BUILTIN_LROUNDL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
_CCCL_API inline long lround(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LROUNDF)
|
||||
return _CCCL_BUILTIN_LROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LROUNDF ^^^ // vvv !_CCCL_BUILTIN_LROUNDF vvv
|
||||
return ::lroundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LROUNDF
|
||||
}
|
||||
|
||||
_CCCL_API inline long lroundf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LROUNDF)
|
||||
return _CCCL_BUILTIN_LROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LROUNDF ^^^ // vvv !_CCCL_BUILTIN_LROUNDF vvv
|
||||
return ::lroundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_LROUNDF
|
||||
}
|
||||
|
||||
_CCCL_API inline long lround(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_LROUND)
|
||||
return _CCCL_BUILTIN_LROUND(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_LROUND ^^^ // vvv !_CCCL_BUILTIN_LROUND vvv
|
||||
return ::lround(__x);
|
||||
#endif // !_CCCL_BUILTIN_LROUND
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline long lround(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LROUNDL)
|
||||
return _CCCL_BUILTIN_LROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LROUNDL ^^^ // vvv !_CCCL_BUILTIN_LROUNDL vvv
|
||||
return ::lroundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LROUNDL
|
||||
}
|
||||
|
||||
_CCCL_API inline long lroundl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_LROUNDL)
|
||||
return _CCCL_BUILTIN_LROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_LROUNDL ^^^ // vvv !_CCCL_BUILTIN_LROUNDL vvv
|
||||
return ::lroundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_LROUNDL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline long lround(__half __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lroundf(__half2float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline long lround(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lroundf(__bfloat162float(__x));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
_CCCL_API inline long lround(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::lround((double) __x);
|
||||
}
|
||||
|
||||
// nearbyint
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_nearbyint) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_NEARBYINTF(...) __builtin_nearbyintf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEARBYINT(...) __builtin_nearbyint(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEARBYINTL(...) __builtin_nearbyintl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_nearbyint)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float nearbyint(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEARBYINTF)
|
||||
return _CCCL_BUILTIN_NEARBYINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEARBYINTF ^^^ // vvv !_CCCL_BUILTIN_NEARBYINTF vvv
|
||||
return ::nearbyintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_NEARBYINTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float nearbyintf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEARBYINTF)
|
||||
return _CCCL_BUILTIN_NEARBYINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEARBYINTF ^^^ // vvv !_CCCL_BUILTIN_NEARBYINTF vvv
|
||||
return ::nearbyintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_NEARBYINTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double nearbyint(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEARBYINT)
|
||||
return _CCCL_BUILTIN_NEARBYINT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEARBYINT ^^^ // vvv !_CCCL_BUILTIN_NEARBYINT vvv
|
||||
return ::nearbyint(__x);
|
||||
#endif // !_CCCL_BUILTIN_NEARBYINT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double nearbyint(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEARBYINTL)
|
||||
return _CCCL_BUILTIN_NEARBYINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEARBYINTL ^^^ // vvv !_CCCL_BUILTIN_NEARBYINTL vvv
|
||||
return ::nearbyintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_NEARBYINTL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double nearbyintl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEARBYINTL)
|
||||
return _CCCL_BUILTIN_NEARBYINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEARBYINTL ^^^ // vvv !_CCCL_BUILTIN_NEARBYINTL vvv
|
||||
return ::nearbyintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_NEARBYINTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half nearbyint(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::nearbyintf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 nearbyint(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::nearbyintf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double nearbyint(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::nearbyint((double) __x);
|
||||
}
|
||||
|
||||
// nextafter
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_nextafter) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_NEXTAFTERF(...) __builtin_nextafterf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEXTAFTER(...) __builtin_nextafter(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEXTAFTERL(...) __builtin_nextafterl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_nextafter)
|
||||
|
||||
// clang-cuda fails with fatal error: error in backend: Undefined external symbol "nextafter"
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_NEXTAFTERF
|
||||
# undef _CCCL_BUILTIN_NEXTAFTER
|
||||
# undef _CCCL_BUILTIN_NEXTAFTERL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
_CCCL_API inline float nextafter(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEXTAFTERF)
|
||||
return _CCCL_BUILTIN_NEXTAFTERF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEXTAFTERF ^^^ // vvv !_CCCL_BUILTIN_NEXTAFTERF vvv
|
||||
return ::nextafterf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_NEXTAFTERF
|
||||
}
|
||||
|
||||
_CCCL_API inline float nextafterf(float __x, float __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEXTAFTERF)
|
||||
return _CCCL_BUILTIN_NEXTAFTERF(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEXTAFTERF ^^^ // vvv !_CCCL_BUILTIN_NEXTAFTERF vvv
|
||||
return ::nextafterf(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_NEXTAFTERF
|
||||
}
|
||||
|
||||
_CCCL_API inline double nextafter(double __x, double __y) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_NEXTAFTER)
|
||||
return _CCCL_BUILTIN_NEXTAFTER(__x, __y);
|
||||
#else // ^^^ _CCCL_BUILTIN_NEXTAFTER ^^^ // vvv !_CCCL_BUILTIN_NEXTAFTER vvv
|
||||
return ::nextafter(__x, __y);
|
||||
#endif // !_CCCL_BUILTIN_NEXTAFTER
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline long double nextafter(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTAFTERL)
|
||||
return _CCCL_BUILTIN_NEXTAFTERL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTAFTERL ^^^ // vvv !_CCCL_BUILTIN_NEXTAFTERL vvv
|
||||
return ::nextafterl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTAFTERL
|
||||
}
|
||||
|
||||
_CCCL_API inline long double nextafterl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTAFTERL)
|
||||
return _CCCL_BUILTIN_NEXTAFTERL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTAFTERL ^^^ // vvv !_CCCL_BUILTIN_NEXTAFTERL vvv
|
||||
return ::nextafterl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTAFTERL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half nextafter(__half __x, __half __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::nextafterf(__half2float(__x), __half2float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 nextafter(__nv_bfloat16 __x, __nv_bfloat16 __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::nextafterf(__bfloat162float(__x), __bfloat162float(__y)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<is_arithmetic_v<_A1> && is_arithmetic_v<_A2>, int> = 0>
|
||||
_CCCL_API inline __promote_t<_A1, _A2> nextafter(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using __result_type = __promote_t<_A1, _A2>;
|
||||
static_assert(!(is_same_v<_A1, __result_type> && is_same_v<_A2, __result_type>) );
|
||||
return ::cuda::std::nextafter(static_cast<__result_type>(__x), static_cast<__result_type>(__y));
|
||||
}
|
||||
|
||||
// nexttoward
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_nexttoward) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_NEXTTOWARDF(...) __builtin_nexttowardf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEXTTOWARD(...) __builtin_nexttoward(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_NEXTTOWARDL(...) __builtin_nexttowardl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_nexttoward)
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
_CCCL_API inline float nexttoward(float __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTTOWARDF)
|
||||
return _CCCL_BUILTIN_NEXTTOWARDF(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTTOWARDF ^^^ // vvv !_CCCL_BUILTIN_NEXTTOWARDF vvv
|
||||
return ::nexttowardf(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTTOWARDF
|
||||
}
|
||||
|
||||
_CCCL_API inline float nexttowardf(float __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTTOWARDF)
|
||||
return _CCCL_BUILTIN_NEXTTOWARDF(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTTOWARDF ^^^ // vvv !_CCCL_BUILTIN_NEXTTOWARDF vvv
|
||||
return ::nexttowardf(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTTOWARDF
|
||||
}
|
||||
|
||||
_CCCL_API inline double nexttoward(double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTTOWARD)
|
||||
return _CCCL_BUILTIN_NEXTTOWARD(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTTOWARD ^^^ // vvv !_CCCL_BUILTIN_NEXTTOWARD vvv
|
||||
return ::nexttoward(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTTOWARD
|
||||
}
|
||||
|
||||
_CCCL_API inline long double nexttoward(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTTOWARDL)
|
||||
return _CCCL_BUILTIN_NEXTTOWARDL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTTOWARDL ^^^ // vvv !_CCCL_BUILTIN_NEXTTOWARDL vvv
|
||||
return ::nexttowardl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTTOWARDL
|
||||
}
|
||||
|
||||
_CCCL_API inline long double nexttowardl(long double __x, long double __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_NEXTTOWARDL)
|
||||
return _CCCL_BUILTIN_NEXTTOWARDL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_NEXTTOWARDL ^^^ // vvv !_CCCL_BUILTIN_NEXTTOWARDL vvv
|
||||
return ::nexttowardl(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_NEXTTOWARDL
|
||||
}
|
||||
|
||||
# if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half nexttoward(__half __x, long double __y) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::nexttowardf(__half2float(__x), __y));
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
# if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 nexttoward(__nv_bfloat16 __x, long double __y) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::nexttowardf(__bfloat162float(__x), __y));
|
||||
}
|
||||
# endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
_CCCL_API inline double nexttoward(_Integer __x, long double __y) noexcept
|
||||
{
|
||||
return ::cuda::std::nexttoward((double) __x, __y);
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
// rint
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_rint) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_RINTF(...) __builtin_rintf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_RINT(...) __builtin_rint(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_RINTL(...) __builtin_rintl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_rint)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float rint(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_RINTF)
|
||||
return _CCCL_BUILTIN_RINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_RINTF ^^^ // vvv !_CCCL_BUILTIN_RINTF vvv
|
||||
return ::rintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_RINTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float rintf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_RINTF)
|
||||
return _CCCL_BUILTIN_RINTF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_RINTF ^^^ // vvv !_CCCL_BUILTIN_RINTF vvv
|
||||
return ::rintf(__x);
|
||||
#endif // !_CCCL_BUILTIN_RINTF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double rint(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_RINT)
|
||||
return _CCCL_BUILTIN_RINT(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_RINT ^^^ // vvv !_CCCL_BUILTIN_RINT vvv
|
||||
return ::rint(__x);
|
||||
#endif // !_CCCL_BUILTIN_RINT
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double rint(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_RINTL)
|
||||
return _CCCL_BUILTIN_RINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_RINTL ^^^ // vvv !_CCCL_BUILTIN_RINTL vvv
|
||||
return ::rintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_RINTL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double rintl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_RINTL)
|
||||
return _CCCL_BUILTIN_RINTL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_RINTL ^^^ // vvv !_CCCL_BUILTIN_RINTL vvv
|
||||
return ::rintl(__x);
|
||||
# endif // !_CCCL_BUILTIN_RINTL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half rint(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::hrint(__x);), (return __float2half(::cuda::std::rint(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 rint(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hrint(__x);), (return __float2bfloat16(::cuda::std::rint(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double rint(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::rint((double) __x);
|
||||
}
|
||||
|
||||
// round
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_round) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ROUNDF(...) __builtin_roundf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ROUND(...) __builtin_round(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_ROUNDL(...) __builtin_roundl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_round)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float round(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ROUNDF)
|
||||
return _CCCL_BUILTIN_ROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ROUNDF ^^^ // vvv !_CCCL_BUILTIN_ROUNDF vvv
|
||||
return ::roundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ROUNDF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float roundf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ROUNDF)
|
||||
return _CCCL_BUILTIN_ROUNDF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ROUNDF ^^^ // vvv !_CCCL_BUILTIN_ROUNDF vvv
|
||||
return ::roundf(__x);
|
||||
#endif // !_CCCL_BUILTIN_ROUNDF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double round(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_ROUND)
|
||||
return _CCCL_BUILTIN_ROUND(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_ROUND ^^^ // vvv !_CCCL_BUILTIN_ROUND vvv
|
||||
return ::round(__x);
|
||||
#endif // !_CCCL_BUILTIN_ROUND
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double round(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ROUNDL)
|
||||
return _CCCL_BUILTIN_ROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ROUNDL ^^^ // vvv !_CCCL_BUILTIN_ROUNDL vvv
|
||||
return ::roundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ROUNDL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double roundl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ROUNDL)
|
||||
return _CCCL_BUILTIN_ROUNDL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_ROUNDL ^^^ // vvv !_CCCL_BUILTIN_ROUNDL vvv
|
||||
return ::roundl(__x);
|
||||
# endif // !_CCCL_BUILTIN_ROUNDL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half round(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::roundf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 round(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::roundf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double round(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::round((double) __x);
|
||||
}
|
||||
|
||||
// trunc
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_trunc) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_TRUNCF(...) __builtin_truncf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TRUNC(...) __builtin_trunc(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TRUNCL(...) __builtin_truncl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_trunc)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float trunc(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TRUNCF)
|
||||
return _CCCL_BUILTIN_TRUNCF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TRUNCF ^^^ // vvv !_CCCL_BUILTIN_TRUNCF vvv
|
||||
return ::truncf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TRUNCF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float truncf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TRUNCF)
|
||||
return _CCCL_BUILTIN_TRUNCF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TRUNCF ^^^ // vvv !_CCCL_BUILTIN_TRUNCF vvv
|
||||
return ::truncf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TRUNCF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double trunc(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TRUNC)
|
||||
return _CCCL_BUILTIN_TRUNC(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TRUNC ^^^ // vvv !_CCCL_BUILTIN_TRUNC vvv
|
||||
return ::trunc(__x);
|
||||
#endif // !_CCCL_BUILTIN_TRUNC
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double trunc(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TRUNCL)
|
||||
return _CCCL_BUILTIN_TRUNCL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TRUNCL ^^^ // vvv !_CCCL_BUILTIN_TRUNCL vvv
|
||||
return ::truncl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TRUNCL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double truncl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TRUNCL)
|
||||
return _CCCL_BUILTIN_TRUNCL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TRUNCL ^^^ // vvv !_CCCL_BUILTIN_TRUNCL vvv
|
||||
return ::truncl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TRUNCL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half trunc(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_IS_DEVICE, (return ::htrunc(__x);), (return __float2half(::cuda::std::trunc(__half2float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 trunc(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::htrunc(__x);), (return __float2bfloat16(::cuda::std::trunc(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double trunc(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::trunc((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_ROUNDING_FUNCTIONS_H
|
||||
56
cccl_upstream/libcudacxx/include/cuda/std/__cmath/signbit.h
Normal file
56
cccl_upstream/libcudacxx/include/cuda/std/__cmath/signbit.h
Normal file
@@ -0,0 +1,56 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of libcu++, the C++ Standard Library for your entire system,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_SIGNBIT_H
|
||||
#define _CUDA_STD___CMATH_SIGNBIT_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__concepts/concept_macros.h>
|
||||
#include <cuda/std/__floating_point/fp.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/limits>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
_CCCL_TEMPLATE(class _Tp)
|
||||
_CCCL_REQUIRES(__is_extended_arithmetic_v<_Tp>)
|
||||
[[nodiscard]] _CCCL_API constexpr bool signbit([[maybe_unused]] _Tp __x) noexcept
|
||||
{
|
||||
if constexpr (!numeric_limits<_Tp>::is_signed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if constexpr (is_integral_v<_Tp>)
|
||||
{
|
||||
return __x < 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ::cuda::std::__fp_get_storage(__x) & __fp_sign_mask_of_v<_Tp>;
|
||||
}
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_SIGNBIT_H
|
||||
239
cccl_upstream/libcudacxx/include/cuda/std/__cmath/traits.h
Normal file
239
cccl_upstream/libcudacxx/include/cuda/std/__cmath/traits.h
Normal file
@@ -0,0 +1,239 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_TRAITS_H
|
||||
#define _CUDA_STD___CMATH_TRAITS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__cmath/isnan.h>
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_extended_arithmetic.h>
|
||||
#include <cuda/std/__type_traits/is_extended_floating_point.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/__type_traits/is_signed.h>
|
||||
#include <cuda/std/__type_traits/promote.h>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// isgreater
|
||||
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool __device_isgreater(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
if (::cuda::std::isnan(__x) || ::cuda::std::isnan(__y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x > __y;
|
||||
}
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isgreater) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISGREATER(...) __builtin_isgreater(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_isgreater)
|
||||
|
||||
#if !_CCCL_COMPILER(NVRTC)
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_API bool __host_isgreater(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISGREATER)
|
||||
return _CCCL_BUILTIN_ISGREATER(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISGREATER ^^^ / vvv !_CCCL_BUILTIN_ISGREATER vvv
|
||||
return ::isgreater(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ISGREATER
|
||||
}
|
||||
#endif // !_CCCL_COMPILER(NVRTC)
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool isgreater(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(return ::cuda::std::__host_isgreater((type) __x, (type) __y);),
|
||||
(return ::cuda::std::__device_isgreater((type) __x, (type) __y);))
|
||||
}
|
||||
|
||||
// isgreaterequal
|
||||
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool __device_isgreaterequal(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
if (::cuda::std::isnan(__x) || ::cuda::std::isnan(__y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x >= __y;
|
||||
}
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isgreaterequal) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISGREATEREQUAL(...) __builtin_isgreaterequal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_isgreaterequal)
|
||||
|
||||
#if !_CCCL_COMPILER(NVRTC)
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_API bool __host_isgreaterequal(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISGREATEREQUAL)
|
||||
return _CCCL_BUILTIN_ISGREATEREQUAL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISGREATEREQUAL ^^^ / vvv !_CCCL_BUILTIN_ISGREATEREQUAL vvv
|
||||
return ::isgreaterequal(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ISGREATEREQUAL
|
||||
}
|
||||
#endif // !_CCCL_COMPILER(NVRTC)
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool isgreaterequal(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(return ::cuda::std::__host_isgreaterequal((type) __x, (type) __y);),
|
||||
(return ::cuda::std::__device_isgreaterequal((type) __x, (type) __y);))
|
||||
}
|
||||
|
||||
// isless
|
||||
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool __device_isless(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
if (::cuda::std::isnan(__x) || ::cuda::std::isnan(__y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x < __y;
|
||||
}
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_isless) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISLESS(...) __builtin_isless(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_isless)
|
||||
|
||||
#if !_CCCL_COMPILER(NVRTC)
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_API bool __host_isless(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISLESS)
|
||||
return _CCCL_BUILTIN_ISLESS(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISLESS ^^^ / vvv !_CCCL_BUILTIN_ISLESS vvv
|
||||
return ::isless(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ISLESS
|
||||
}
|
||||
#endif // !_CCCL_COMPILER(NVRTC)
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool isless(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(return ::cuda::std::__host_isless((type) __x, (type) __y);),
|
||||
(return ::cuda::std::__device_isless((type) __x, (type) __y);))
|
||||
}
|
||||
|
||||
// islessequal
|
||||
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool __device_islessequal(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
if (::cuda::std::isnan(__x) || ::cuda::std::isnan(__y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x <= __y;
|
||||
}
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_islessequal) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISLESSEQUAL(...) __builtin_islessequal(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_islessequal)
|
||||
|
||||
#if !_CCCL_COMPILER(NVRTC)
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_API bool __host_islessequal(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISLESSEQUAL)
|
||||
return _CCCL_BUILTIN_ISLESSEQUAL(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISLESSEQUAL ^^^ / vvv !_CCCL_BUILTIN_ISLESSEQUAL vvv
|
||||
return ::islessequal(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ISLESSEQUAL
|
||||
}
|
||||
#endif // !_CCCL_COMPILER(NVRTC)
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool islessequal(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(return ::cuda::std::__host_islessequal((type) __x, (type) __y);),
|
||||
(return ::cuda::std::__device_islessequal((type) __x, (type) __y);))
|
||||
}
|
||||
|
||||
// islessgreater
|
||||
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool __device_islessgreater(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
if (::cuda::std::isnan(__x) || ::cuda::std::isnan(__y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return __x < __y || __x > __y;
|
||||
}
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_islessgreater) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_ISLESSGREATER(...) __builtin_islessgreater(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_islessgreater)
|
||||
|
||||
#if !_CCCL_COMPILER(NVRTC)
|
||||
template <class _A1, enable_if_t<__is_extended_arithmetic_v<_A1>, int> = 0>
|
||||
[[nodiscard]] _CCCL_HOST_API bool __host_islessgreater(_A1 __x, _A1 __y) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_ISLESSGREATER)
|
||||
return _CCCL_BUILTIN_ISLESSGREATER(__x, __y);
|
||||
# else // ^^^ _CCCL_BUILTIN_ISLESSGREATER ^^^ / vvv !_CCCL_BUILTIN_ISLESSGREATER vvv
|
||||
return ::islessgreater(__x, __y);
|
||||
# endif // !_CCCL_BUILTIN_ISLESSGREATER
|
||||
}
|
||||
#endif // !_CCCL_COMPILER(NVRTC)
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API bool islessgreater(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
NV_IF_ELSE_TARGET(NV_IS_HOST,
|
||||
(return ::cuda::std::__host_islessgreater((type) __x, (type) __y);),
|
||||
(return ::cuda::std::__device_islessgreater((type) __x, (type) __y);))
|
||||
}
|
||||
|
||||
// isunordered
|
||||
|
||||
template <class _A1, class _A2, enable_if_t<__is_extended_arithmetic_v<_A1> && __is_extended_arithmetic_v<_A2>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline bool isunordered(_A1 __x, _A2 __y) noexcept
|
||||
{
|
||||
using type = __promote_t<_A1, _A2>;
|
||||
return ::cuda::std::isnan((type) __x) || ::cuda::std::isnan((type) __y);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_TRAITS_H
|
||||
@@ -0,0 +1,324 @@
|
||||
// -*- C++ -*-
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef _CUDA_STD___CMATH_TRIGONOMETRIC_FUNCTIONS_H
|
||||
#define _CUDA_STD___CMATH_TRIGONOMETRIC_FUNCTIONS_H
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
|
||||
# pragma GCC system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
|
||||
# pragma clang system_header
|
||||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
|
||||
# pragma system_header
|
||||
#endif // no system header
|
||||
|
||||
#include <cuda/std/__floating_point/cuda_fp_types.h>
|
||||
#include <cuda/std/__host_stdlib/math.h>
|
||||
#include <cuda/std/__type_traits/enable_if.h>
|
||||
#include <cuda/std/__type_traits/is_integral.h>
|
||||
#include <cuda/std/cstdint>
|
||||
|
||||
#include <nv/target>
|
||||
|
||||
#include <cuda/std/__cccl/prologue.h>
|
||||
|
||||
_CCCL_BEGIN_NAMESPACE_CUDA_STD
|
||||
|
||||
// cos
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_cos) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_COSF(...) __builtin_cosf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_COS(...) __builtin_cos(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_COSL(...) __builtin_cosl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_cos)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_COSF
|
||||
# undef _CCCL_BUILTIN_COS
|
||||
# undef _CCCL_BUILTIN_COSL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float cos(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COSF)
|
||||
return _CCCL_BUILTIN_COSF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COSF ^^^ / vvv !_CCCL_BUILTIN_COSF vvv
|
||||
return ::cosf(__x);
|
||||
#endif // !_CCCL_BUILTIN_COSF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float cosf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COSF)
|
||||
return _CCCL_BUILTIN_COSF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COSF ^^^ / vvv !_CCCL_BUILTIN_COSF vvv
|
||||
return ::cosf(__x);
|
||||
#endif // !_CCCL_BUILTIN_COSF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double cos(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_COS)
|
||||
return _CCCL_BUILTIN_COS(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_COS ^^^ / vvv !_CCCL_BUILTIN_COS vvv
|
||||
return ::cos(__x);
|
||||
#endif // !_CCCL_BUILTIN_COS
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double cos(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_COSL)
|
||||
return _CCCL_BUILTIN_COSL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_COSL ^^^ / vvv !_CCCL_BUILTIN_COSL vvv
|
||||
return ::cosl(__x);
|
||||
# endif // !_CCCL_BUILTIN_COSL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double cosl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_COSL)
|
||||
return _CCCL_BUILTIN_COSL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_COSL ^^^ / vvv !_CCCL_BUILTIN_COSL vvv
|
||||
return ::cosl(__x);
|
||||
# endif // !_CCCL_BUILTIN_COSL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half cos(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_53, (return ::hcos(__x);), ({
|
||||
float __xf = __half2float(__x);
|
||||
__xf = ::cuda::std::cosf(__xf);
|
||||
__half_raw __ret_repr = ::__float2half_rn(__xf);
|
||||
|
||||
uint16_t __repr = __half_raw(__x).x;
|
||||
switch (__repr)
|
||||
{
|
||||
case 11132:
|
||||
case 43900:
|
||||
__ret_repr.x += 1;
|
||||
break;
|
||||
|
||||
default:;
|
||||
}
|
||||
|
||||
return __ret_repr;
|
||||
}))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 cos(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hcos(__x);), (return __float2bfloat16(::cuda::std::cosf(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double cos(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::cos((double) __x);
|
||||
}
|
||||
|
||||
// sin
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_sin) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_SINF(...) __builtin_sinf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SIN(...) __builtin_sin(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_SINL(...) __builtin_sinl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_sin)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_SINF
|
||||
# undef _CCCL_BUILTIN_SIN
|
||||
# undef _CCCL_BUILTIN_SINL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float sin(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SINF)
|
||||
return _CCCL_BUILTIN_SINF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SINF ^^^ / vvv !_CCCL_BUILTIN_SINF vvv
|
||||
return ::sinf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SINF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float sinf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SINF)
|
||||
return _CCCL_BUILTIN_SINF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SINF ^^^ / vvv !_CCCL_BUILTIN_SINF vvv
|
||||
return ::sinf(__x);
|
||||
#endif // !_CCCL_BUILTIN_SINF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double sin(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_SIN)
|
||||
return _CCCL_BUILTIN_SIN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_SIN ^^^ / vvv !_CCCL_BUILTIN_SIN vvv
|
||||
return ::sin(__x);
|
||||
#endif // !_CCCL_BUILTIN_SIN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double sin(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SINL)
|
||||
return _CCCL_BUILTIN_SINL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SINL ^^^ / vvv !_CCCL_BUILTIN_SINL vvv
|
||||
return ::sinl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SINL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double sinl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_SINL)
|
||||
return _CCCL_BUILTIN_SINL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_SINL ^^^ / vvv !_CCCL_BUILTIN_SINL vvv
|
||||
return ::sinl(__x);
|
||||
# endif // !_CCCL_BUILTIN_SINL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half sin(__half __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(NV_PROVIDES_SM_53, (return ::hsin(__x);), ({
|
||||
float __xf = __half2float(__x);
|
||||
__xf = ::cuda::std::sinf(__xf);
|
||||
__half_raw __ret_repr = ::__float2half_rn(__xf);
|
||||
|
||||
uint16_t __repr = __half_raw(__x).x;
|
||||
switch (__repr)
|
||||
{
|
||||
case 12979:
|
||||
case 45747:
|
||||
__ret_repr.x += 1;
|
||||
break;
|
||||
|
||||
case 23728:
|
||||
case 56496:
|
||||
__ret_repr.x -= 1;
|
||||
break;
|
||||
|
||||
default:;
|
||||
}
|
||||
|
||||
return __ret_repr;
|
||||
}))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 sin(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
NV_IF_ELSE_TARGET(
|
||||
NV_IS_DEVICE, (return ::hsin(__x);), (return __float2bfloat16(::cuda::std::sinf(__bfloat162float(__x)));))
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double sin(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::sin((double) __x);
|
||||
}
|
||||
|
||||
// tan
|
||||
|
||||
#if _CCCL_CHECK_BUILTIN(builtin_tan) || _CCCL_COMPILER(GCC)
|
||||
# define _CCCL_BUILTIN_TANF(...) __builtin_tanf(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TAN(...) __builtin_tan(__VA_ARGS__)
|
||||
# define _CCCL_BUILTIN_TANL(...) __builtin_tanl(__VA_ARGS__)
|
||||
#endif // _CCCL_CHECK_BUILTIN(builtin_tan)
|
||||
|
||||
#if _CCCL_CUDA_COMPILER(CLANG)
|
||||
# undef _CCCL_BUILTIN_TANF
|
||||
# undef _CCCL_BUILTIN_TAN
|
||||
# undef _CCCL_BUILTIN_TANL
|
||||
#endif // _CCCL_CUDA_COMPILER(CLANG)
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float tan(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TANF)
|
||||
return _CCCL_BUILTIN_TANF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TANF ^^^ / vvv !_CCCL_BUILTIN_TANF vvv
|
||||
return ::tanf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TANF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline float tanf(float __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TANF)
|
||||
return _CCCL_BUILTIN_TANF(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TANF ^^^ / vvv !_CCCL_BUILTIN_TANF vvv
|
||||
return ::tanf(__x);
|
||||
#endif // !_CCCL_BUILTIN_TANF
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline double tan(double __x) noexcept
|
||||
{
|
||||
#if defined(_CCCL_BUILTIN_TAN)
|
||||
return _CCCL_BUILTIN_TAN(__x);
|
||||
#else // ^^^ _CCCL_BUILTIN_TAN ^^^ / vvv !_CCCL_BUILTIN_TAN vvv
|
||||
return ::tan(__x);
|
||||
#endif // !_CCCL_BUILTIN_TAN
|
||||
}
|
||||
|
||||
#if _CCCL_HAS_LONG_DOUBLE()
|
||||
[[nodiscard]] _CCCL_API inline long double tan(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TANL)
|
||||
return _CCCL_BUILTIN_TANL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TANL ^^^ / vvv !_CCCL_BUILTIN_TANL vvv
|
||||
return ::tanl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TANL
|
||||
}
|
||||
|
||||
[[nodiscard]] _CCCL_API inline long double tanl(long double __x) noexcept
|
||||
{
|
||||
# if defined(_CCCL_BUILTIN_TANL)
|
||||
return _CCCL_BUILTIN_TANL(__x);
|
||||
# else // ^^^ _CCCL_BUILTIN_TANL ^^^ / vvv !_CCCL_BUILTIN_TANL vvv
|
||||
return ::tanl(__x);
|
||||
# endif // !_CCCL_BUILTIN_TANL
|
||||
}
|
||||
#endif // _CCCL_HAS_LONG_DOUBLE()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVFP16()
|
||||
[[nodiscard]] _CCCL_API inline __half tan(__half __x) noexcept
|
||||
{
|
||||
return __float2half(::cuda::std::tanf(__half2float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVFP16()
|
||||
|
||||
#if _LIBCUDACXX_HAS_NVBF16()
|
||||
[[nodiscard]] _CCCL_API inline __nv_bfloat16 tan(__nv_bfloat16 __x) noexcept
|
||||
{
|
||||
return __float2bfloat16(::cuda::std::tanf(__bfloat162float(__x)));
|
||||
}
|
||||
#endif // _LIBCUDACXX_HAS_NVBF16()
|
||||
|
||||
template <class _Integer, enable_if_t<is_integral_v<_Integer>, int> = 0>
|
||||
[[nodiscard]] _CCCL_API inline double tan(_Integer __x) noexcept
|
||||
{
|
||||
return ::cuda::std::tan((double) __x);
|
||||
}
|
||||
|
||||
_CCCL_END_NAMESPACE_CUDA_STD
|
||||
|
||||
#include <cuda/std/__cccl/epilogue.h>
|
||||
|
||||
#endif // _CUDA_STD___CMATH_TRIGONOMETRIC_FUNCTIONS_H
|
||||
Reference in New Issue
Block a user