## File: Representation-of-complex-numbers.html

package info (click to toggle)
gsl-ref-html 2.3-1
• area: non-free
• in suites: bullseye, buster, sid
• size: 6,876 kB
• ctags: 4,574
• sloc: makefile: 35
 file content (145 lines) | stat: -rw-r--r-- 6,871 bytes parent folder | download
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145  GNU Scientific Library – Reference Manual: Representation of complex numbers

5.1 Representation of complex numbers

Complex numbers are represented using the type gsl_complex. The internal representation of this type may vary across platforms and should not be accessed directly. The functions and macros described below allow complex numbers to be manipulated in a portable way.

For reference, the default form of the gsl_complex type is given by the following struct,

typedef struct {   double dat[2]; } gsl_complex;

The real and imaginary part are stored in contiguous elements of a two element array. This eliminates any padding between the real and imaginary parts, dat[0] and dat[1], allowing the struct to be mapped correctly onto packed complex arrays.

Function: gsl_complex gsl_complex_rect (double x, double y)

This function uses the rectangular Cartesian components (x,y) to return the complex number z = x + i y. An inline version of this function is used when HAVE_INLINE is defined.

Function: gsl_complex gsl_complex_polar (double r, double theta)

This function returns the complex number z = r \exp(i \theta) = r (\cos(\theta) + i \sin(\theta)) from the polar representation (r,theta).

Macro: GSL_REAL (z)
Macro: GSL_IMAG (z)

These macros return the real and imaginary parts of the complex number z.

Macro: GSL_SET_COMPLEX (zp, x, y)

This macro uses the Cartesian components (x,y) to set the real and imaginary parts of the complex number pointed to by zp. For example,

GSL_SET_COMPLEX(&z, 3, 4)

sets z to be 3 + 4i.

Macro: GSL_SET_REAL (zp,x)
Macro: GSL_SET_IMAG (zp,y)

These macros allow the real and imaginary parts of the complex number pointed to by zp to be set independently.