diff --git a/sycl/doc/extensions/proposed/sycl_ext_oneapi_complex.asciidoc b/sycl/doc/extensions/proposed/sycl_ext_oneapi_complex.asciidoc index 1c53ccc9af70c..c663a2c6d7d3d 100644 --- a/sycl/doc/extensions/proposed/sycl_ext_oneapi_complex.asciidoc +++ b/sycl/doc/extensions/proposed/sycl_ext_oneapi_complex.asciidoc @@ -438,6 +438,33 @@ mathematical operation. |Compute the hyperbolic tangent of complex number x. |=== + +=== Suffixes for complex number literals + +This proposal describes literal suffixes for constructing complex number literals. +The suffixes `i` and `if` create complex numbers of the types `complex` and `complex` respectively, with their imaginary part denoted by the given literal number and the real part being zero. + +```C++ +namespace sycl { +namespace ext { +namespace oneapi { + +namespace literals { +namespace complex_literals { +constexpr complex operator""i(long double x); +constexpr complex operator""i(unsigned long long x); + +constexpr complex operator""if(long double x); +constexpr complex operator""if(unsigned long long x); +} // namespace complex_literals +} // namespace literals + +} // namespace oneapi +} // namespace ext +} // namespace sycl +``` + + == Implementation notes The complex mathematical operations can all be defined using SYCL built-ins. diff --git a/sycl/include/sycl/ext/oneapi/experimental/sycl_complex.hpp b/sycl/include/sycl/ext/oneapi/experimental/sycl_complex.hpp index 0f8223286b852..cc2e83d754287 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/sycl_complex.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/sycl_complex.hpp @@ -979,6 +979,27 @@ tan(const complex<_Tp> &__x) { return complex<_Tp>(__z.imag(), -__z.real()); } +// Literal suffix for complex number literals [complex.literals] +inline namespace literals { +inline namespace complex_literals { +constexpr complex operator""i(long double __im) { + return {0.0, static_cast(__im)}; +} + +constexpr complex operator""i(unsigned long long __im) { + return {0.0, static_cast(__im)}; +} + +constexpr complex operator""if(long double __im) { + return {0.0f, static_cast(__im)}; +} + +constexpr complex operator""if(unsigned long long __im) { + return {0.0f, static_cast(__im)}; +} +} // namespace complex_literals +} // namespace literals + } // namespace experimental } // namespace oneapi } // namespace ext diff --git a/sycl/test/extensions/test_complex.cpp b/sycl/test/extensions/test_complex.cpp index 60b466901e0d8..1aae7d5a0c790 100644 --- a/sycl/test/extensions/test_complex.cpp +++ b/sycl/test/extensions/test_complex.cpp @@ -186,6 +186,16 @@ void check_sycl_constructor_from_std() { } } +// Check types for sycl complex constructed from literals +void check_sycl_complex_literals() { + static_assert( + std::is_same_v>); + static_assert( + std::is_same_v>); +} + int main() { check_math_function_types(); check_math_operator_types(); @@ -195,5 +205,7 @@ int main() { check_std_to_sycl_conversion(); check_sycl_constructor_from_std(); + check_sycl_complex_literals(); + return 0; }