<cuda/std/complex>#
2026-10-01
3 min read time
This page documents the cuda::std::complex support in libhipcxx, including omissions for long double and literals with NVCC, and extensions for infinity handling and half/bfloat16 types.
Omissions#
When using libhipcxx with NVCC, complex does not support long double or complex literals (_i, _if, and _il).
NVCC warns on any usage of long double in device code, because long double will be demoted to double in device code.
This warning can be suppressed silenced with #pragmas, but only globally, not just when using complex.
User-defined floating-point literals must be specified in terms of long double, so they lead to warnings
that are unable to be suppressed.
Extensions#
Handling of infinities
Our implementation by default recovers infinite values during multiplication and division. This adds a significant runtime overhead, so we allow disabling that canonicalization if it is not desired.
Definition of
LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONSdisables canonicalization for both multiplication and division.Definition of
LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_MULTIPLICATIONorLIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_DIVISIONdisables canonicalization for multiplication or division individually.Support for half and bfloat16 (since libhipcxx 2.4.0)
Our implementation includes support for the
__halftype from<cuda_fp16.h>, when the CUDA toolkit version is at least 12.2, and whenCCCL_DISABLE_FP16_SUPPORTis not defined.This is detected automatically when compiling through NVCC. If you are compiling a host-only translation unit directly with the host compiler, you must define the macro
LIBCUDACXX_ENABLE_HOST_NVFP16prior to including any libhipcxx headers, and you must ensure that the<cuda_fp16.h>header that’s found by the compiler comes from a CUDA toolkit version 12.2 or higher.Our implementation includes support for the
__nv_bfloat16type from<cuda_bf16.h>, when the conditions for the support of__halfare fulfilled, and whenCCCL_DISABLE_BF16_SUPPORTandCCCL_DISABLE_FP16_SUPPORTare not defined.C++20 constexpr
<complex>is available in C++14.