GNU MPC 1.0.2: Assigning Complex Numbers

Next: Converting Complex Numbers, Previous: Initializing Complex Numbers, Up: Complex Functions [Index]

### 5.2 Assignment Functions

These functions assign new values to already initialized complex numbers (see Initializing Complex Numbers). When using any functions with `intmax_t` or `uintmax_t` parameters, you must include `<stdint.h>` or `<inttypes.h>` before `mpc.h`, to allow `mpc.h` to define prototypes for these functions. Similarly, functions with parameters of type `complex` or `long complex` are defined only if `<complex.h>` is included before `mpc.h`. If you need assignment functions that are not in the current API, you can define them using the `MPC_SET_X_Y` macro (see Advanced Functions).

Function: int mpc_set (mpc_t rop, mpc_t op, mpc_rnd_t rnd)

  Set the value of rop from op, rounded to the precision of rop with the given rounding mode rnd.

Function: int mpc_set_ui (mpc_t rop, unsigned long int op, mpc_rnd_t rnd)
Function: int mpc_set_si (mpc_t rop, long int op, mpc_rnd_t rnd)
Function: int mpc_set_uj (mpc_t rop, uintmax_t op, mpc_rnd_t rnd)
Function: int mpc_set_sj (mpc_t rop, intmax_t op, mpc_rnd_t rnd)
Function: int mpc_set_d (mpc_t rop, double op, mpc_rnd_t rnd)
Function: int mpc_set_ld (mpc_t rop, long double op, mpc_rnd_t rnd)
Function: int mpc_set_dc (mpc_t rop, double _Complex op, mpc_rnd_t rnd)
Function: int mpc_set_ldc (mpc_t rop, long double _Complex op, mpc_rnd_t rnd)
Function: int mpc_set_z (mpc_t rop, mpz_t op mpc_rnd_t rnd)
Function: int mpc_set_q (mpc_t rop, mpq_t op mpc_rnd_t rnd)
Function: int mpc_set_f (mpc_t rop, mpf_t op mpc_rnd_t rnd)
Function: int mpc_set_fr (mpc_t rop, mpfr_t op, mpc_rnd_t rnd)

  Set the value of rop from op, rounded to the precision of rop with the given rounding mode rnd. The argument op is interpreted as real, so the imaginary part of rop is set to zero with a positive sign. Please note that even a `long int` may have to be rounded, if the destination precision is less than the machine word width. For `mpc_set_d`, be careful that the input number op may not be exactly representable as a double-precision number (this happens for 0.1 for instance), in which case it is first rounded by the C compiler to a double-precision number, and then only to a complex number.

Function: int mpc_set_ui_ui (mpc_t rop, unsigned long int op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_set_si_si (mpc_t rop, long int op1, long int op2, mpc_rnd_t rnd)
Function: int mpc_set_uj_uj (mpc_t rop, uintmax_t op1, uintmax_t op2, mpc_rnd_t rnd)
Function: int mpc_set_sj_sj (mpc_t rop, intmax_t op1, intmax_t op2, mpc_rnd_t rnd)
Function: int mpc_set_d_d (mpc_t rop, double op1, double op2, mpc_rnd_t rnd)
Function: int mpc_set_ld_ld (mpc_t rop, long double op1, long double op2, mpc_rnd_t rnd)
Function: int mpc_set_z_z (mpc_t rop, mpz_t op1, mpz_t op2, mpc_rnd_t rnd)
Function: int mpc_set_q_q (mpc_t rop, mpq_t op1, mpq_t op2, mpc_rnd_t rnd)
Function: int mpc_set_f_f (mpc_t rop, mpf_t op1, mpf_t op2, mpc_rnd_t rnd)
Function: int mpc_set_fr_fr (mpc_t rop, mpfr_t op1, mpfr_t op2, mpc_rnd_t rnd)

  Set the real part of rop from op1, and its imaginary part from op2, according to the rounding mode rnd.

  Beware that the behaviour of `mpc_set_fr_fr` is undefined if op1 or op2 is a pointer to the real or imaginary part of rop. To exchange the real and the imaginary part of a complex number, either use `mpfr_swap (mpc_realref (rop), mpc_imagref (rop))`, which also exchanges the precisions of the two parts; or use a temporary variable.

For functions assigning complex variables from strings or input streams, see String and Stream Input and Output.

Function: void mpc_set_nan (mpc_t rop)

  Set rop to Nan+i*NaN.

Function: void mpc_swap (mpc_t op1, mpc_t op2)

  Swap the values of op1 and op2 efficiently. Warning: The precisions are exchanged, too; in case these are different, `mpc_swap` is thus not equivalent to three `mpc_set` calls using a third auxiliary variable.

Next: Converting Complex Numbers, Previous: Initializing Complex Numbers, Up: Complex Functions [Index]