<cuda/std/complex>#

2026-10-07

1 min read time

Applies to Linux and Windows

This page documents the cuda::std::complex support in libhipcxx, including the omission of complex literals and extensions for infinity handling and half and bfloat16 types.

Omissions#

When a translation unit is compiled with hipcc, complex does not provide the complex literals i, if, and il. Their suffixes do not start with an underscore, a form that is reserved for the standard library. The literals are available when a translation unit is compiled directly with the host compiler.

complex<long double> is available, but long double is demoted to double in device code. The type therefore has a different size in host and device code and must not be shared between them.

Extensions#

  • Handling of infinities

    Our implementation by default recovers infinite values during multiplication and division. The recovery only runs when the unrecovered result is NaN in both components, but it enlarges the generated code considerably, so we allow disabling that canonicalization if it is not desired.

    Definition of LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_OPERATIONS disables canonicalization for both multiplication and division.

    Definition of LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_MULTIPLICATION or LIBCUDACXX_ENABLE_SIMPLIFIED_COMPLEX_DIVISION disables canonicalization for multiplication or division individually.

  • Support for half and bfloat16

    Our implementation includes support for the __half type from <hip/hip_fp16.h> and the __hip_bfloat16 type from <hip/hip_bf16.h>. Both are available when the translation unit is compiled with hipcc, including host-only translation units. They are not available when a translation unit is compiled directly with the host compiler.

  • C++20 constexpr <complex> is available in C++17.