Skip to main content
IBM Quantum Platform

QkComplex64

A complex, double-precision number representation. This data type is used to safely use complex numbers within Qiskit, but is not necessarily designed for easy manipulation on user-side. Instead, we provide functions to convert from compiler-native representation (e.g. double complex for GNU or Clang compilers), which allow for ergonomic handling, to Qiskit’s QkComplex64 representation, which is meant for passing into Qiskit functions and structs.

Explicitly, Qiskit assumes the compiler-native complex number type in C to be _Dcomplex for Windows MSVC (if _MSC_VER is defined) and double _Complex otherwise. In C++ (if __cplusplus is defined), the complex number type is always std::complex<double>.


Data types

QkComplex64

struct QkComplex64

A complex double.

See also qk_complex64_to_native and qk_complex64_from_native to convert this struct to (or from) a compiler-native complex number representation.

double re

double im


Functions

static CMPLX_DOUBLE qk_complex64_to_native(QkComplex64 *value)

Convert a QkComplex64 to a compiler-native complex number representation. Note that CMPLX_DOUBLE is a placeholder for the compiler-native complex number type, see the top of the page for more details.

Example

Assuming a GNU/clang compiler with double complex as native complex number, we have

QkComplex64 qk_value = {1, 1}; // represents 1 + i
double complex value = qk_complex64_to_native(&qk_value);

Safety

Behavior is undefined if value is not a valid, non-null pointer to a QkComplex64.

Parameters

value – A pointer to the QkComplex64 to convert.

Returns

A native representation of the complex number.

static QkComplex64 qk_complex64_from_native(CMPLX_DOUBLE *value)

Convert a compiler-native complex number to a QkComplex64. Note that CMPLX_DOUBLE is a placeholder for the compiler-native complex number type, see the top of the page for more details.

Example

Assuming a GNU/clang compiler with double complex as native complex number, we have

double complex value = 1 + I;
QkComplex64 qk_value = qk_complex64_from_native(&value);

Safety

Behavior is undefined if value is not a valid, non-null pointer to a QkComplex64.

Parameters

value – A pointer to the native complex number.

Returns

A QkComplex64 representation of the complex number.

Was this page helpful?
Report a bug or request content on GitHub.