logo
pub const Complex_Functions: ();
Expand description

This constant is a place-holder for documentation; do not use it in code.


Next: , Previous: , Up: GNU MPC   [Index]

5 Complex Functions

The complex functions expect arguments of type mpc_t.

The GNU MPC floating-point functions have an interface that is similar to the GNU MP integer functions. The function prefix for operations on complex numbers is mpc_.

The precision of a computation is defined as follows: Compute the requested operation exactly (with “infinite precision”), and round the result to the destination variable precision with the given rounding mode.

The GNU MPC complex functions are intended to be a smooth extension of the IEEE P754 arithmetic. The results obtained on one computer should not differ from the results obtained on a computer with a different word size.


5.1 Initialization Functions

An mpc_t object must be initialised before storing the first value in it. The functions mpc_init2 and mpc_init3 are used for that purpose.

Function: void mpc_init2 (mpc_t z, mpfr_prec_t prec)

Initialise z to precision prec bits and set its real and imaginary parts to NaN. Normally, a variable should be initialised once only or at least be cleared, using mpc_clear, between initializations.

Function: void mpc_init3 (mpc_t z, mpfr_prec_t prec_r, mpfr_prec_t prec_i)

Initialise z with the precision of its real part being prec_r bits and the precision of its imaginary part being prec_i bits, and set the real and imaginary parts to NaN.

Function: void mpc_clear (mpc_t z)

Free the space occupied by z. Make sure to call this function for all mpc_t variables when you are done with them.

Here is an example on how to initialise complex variables:

{
  mpc_t x, y;
  mpc_init2 (x, 256);		/* precision exactly 256 bits */
  mpc_init3 (y, 100, 50);	/* 100/50 bits for the real/imaginary part */
  …
  mpc_clear (x);
  mpc_clear (y);
}

The following function is useful for changing the precision during a calculation. A typical use would be for adjusting the precision gradually in iterative algorithms like Newton-Raphson, making the computation precision closely match the actual accurate part of the numbers.

Function: void mpc_set_prec (mpc_t x, mpfr_prec_t prec)

Reset the precision of x to be exactly prec bits, and set its real/imaginary parts to NaN. The previous value stored in x is lost. It is equivalent to a call to mpc_clear(x) followed by a call to mpc_init2(x, prec), but more efficient as no allocation is done in case the current allocated space for the mantissa of x is sufficient.

Function: mpfr_prec_t mpc_get_prec (const mpc_t x)

If the real and imaginary part of x have the same precision, it is returned, otherwise, 0 is returned.

Function: void mpc_get_prec2 (mpfr_prec_t* pr, mpfr_prec_t* pi, const mpc_t x)

Returns the precision of the real part of x via pr and of its imaginary part via pi.


5.2 Assignment Functions

These functions assign new values to already initialised complex numbers (see Initialization Functions). 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, const 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, const mpz_t op mpc_rnd_t rnd)
Function: int mpc_set_q (mpc_t rop, const mpq_t op mpc_rnd_t rnd)
Function: int mpc_set_f (mpc_t rop, const mpf_t op mpc_rnd_t rnd)
Function: int mpc_set_fr (mpc_t rop, const 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, const mpz_t op1, const mpz_t op2, mpc_rnd_t rnd)
Function: int mpc_set_q_q (mpc_t rop, const mpq_t op1, const mpq_t op2, mpc_rnd_t rnd)
Function: int mpc_set_f_f (mpc_t rop, const mpf_t op1, const mpf_t op2, mpc_rnd_t rnd)
Function: int mpc_set_fr_fr (mpc_t rop, const mpfr_t op1, const 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.


5.3 Conversion Functions

The following functions are available only if <complex.h> is included before mpc.h.

Function: double _Complex mpc_get_dc (const mpc_t op, mpc_rnd_t rnd)
Function: long double _Complex mpc_get_ldc (mpc_t op, mpc_rnd_t rnd)

Convert op to a C complex number, using the rounding mode rnd.

For functions converting complex variables to strings or stream output, see String and Stream Input and Output.


5.4 String and Stream Input and Output

Function: int mpc_strtoc (mpc_t rop, const char *nptr, char **endptr, int base, mpc_rnd_t rnd)

Read a complex number from a string nptr in base base, rounded to the precision of rop with the given rounding mode rnd. The base must be either 0 or a number from 2 to 36 (otherwise the behaviour is undefined). If nptr starts with valid data, the result is stored in rop, the usual inexact value is returned (see Return Value) and, if endptr is not the null pointer, *endptr points to the character just after the valid data. Otherwise, rop is set to NaN + i * NaN, -1 is returned and, if endptr is not the null pointer, the value of nptr is stored in the location referenced by endptr.

The expected form of a complex number string is either a real number (an optional leading whitespace, an optional sign followed by a floating-point number), or a pair of real numbers in parentheses separated by whitespace. If a real number is read, the missing imaginary part is set to +0. The form of a floating-point number depends on the base and is described in the documentation of mpfr_strtofr in the GNU MPFR manual. For instance, "3.1415926", "(1.25e+7 +.17)", "(@nan@ 2)" and "(-0 -7)" are valid strings for base = 10. If base = 0, then a prefix may be used to indicate the base in which the floating-point number is written. Use prefix ’0b’ for binary numbers, prefix ’0x’ for hexadecimal numbers, and no prefix for decimal numbers. The real and imaginary part may then be written in different bases. For instance, "(1.024e+3 +2.05e+3)" and "(0b1p+10 +0x802)" are valid strings for base=0 and represent the same value.

Function: int mpc_set_str (mpc_t rop, const char *s, int base, mpc_rnd_t rnd)

Set rop to the value of the string s in base base, rounded to the precision of rop with the given rounding mode rnd. See the documentation of mpc_strtoc for a detailed description of the valid string formats. Contrarily to mpc_strtoc, mpc_set_str requires the whole string to represent a valid complex number (potentially followed by additional white space). This function returns the usual inexact value (see Return Value) if the entire string up to the final null character is a valid number in base base; otherwise it returns -1, and rop is set to NaN+i*NaN.

Function: char * mpc_get_str (int b, size_t n, const mpc_t op, mpc_rnd_t rnd)

Convert op to a string containing its real and imaginary parts, separated by a space and enclosed in a pair of parentheses. The numbers are written in base b (which may vary from 2 to 36) and rounded according to rnd. The number of significant digits, at least 2, is given by n. It is also possible to let n be zero, in which case the number of digits is chosen large enough so that re-reading the printed value with the same precision, assuming both output and input use rounding to nearest, will recover the original value of op. Note that mpc_get_str uses the decimal point of the current locale if available, and ‘.’ otherwise.

The string is generated using the current memory allocation function (malloc by default, unless it has been modified using the custom memory allocation interface of gmp); once it is not needed any more, it should be freed by calling mpc_free_str.

Function: void mpc_free_str (char *str)

Free the string str, which needs to have been allocated by a call to mpc_get_str.

The following two functions read numbers from input streams and write them to output streams. When using any of these functions, you need to include stdio.h before mpc.h.

Function: int mpc_inp_str (mpc_t rop, FILE *stream, size_t *read, int base, mpc_rnd_t rnd)

Input a string in base base in the same format as for mpc_strtoc from stdio stream stream, rounded according to rnd, and put the read complex number into rop. If stream is the null pointer, rop is read from stdin. Return the usual inexact value; if an error occurs, set rop to NaN + i * NaN and return -1. If read is not the null pointer, it is set to the number of read characters.

Unlike mpc_strtoc, the function mpc_inp_str does not possess perfect knowledge of the string to transform and has to read it character by character, so it behaves slightly differently: It tries to read a string describing a complex number and processes this string through a call to mpc_set_str. Precisely, after skipping optional whitespace, a minimal string is read according to the regular expression mpfr | '(' \s* mpfr \s+ mpfr \s* ')', where \s denotes a whitespace, and mpfr is either a string containing neither whitespaces nor parentheses, or nan(n-char-sequence) or @nan@(n-char-sequence) (regardless of capitalisation) with n-char-sequence a string of ascii letters, digits or '_'.

For instance, upon input of "nan(13 1)", the function mpc_inp_str starts to recognise a value of NaN followed by an n-char-sequence indicated by the opening parenthesis; as soon as the space is reached, it becomes clear that the expression in parentheses is not an n-char-sequence, and the error flag -1 is returned after 6 characters have been consumed from the stream (the whitespace itself remaining in the stream). The function mpc_strtoc, on the other hand, may track back when reaching the whitespace; it treats the string as the two successive complex numbers NaN + i * 0 and 13 + i. It is thus recommended to have a whitespace follow each floating point number to avoid this problem.

Function: size_t mpc_out_str (FILE *stream, int base, size_t n_digits, const mpc_t op, mpc_rnd_t rnd)

Output op on stdio stream stream in base base, rounded according to rnd, in the same format as for mpc_strtoc If stream is the null pointer, rop is written to stdout.

Return the number of characters written.


5.5 Comparison Functions

Function: int mpc_cmp (const mpc_t op1, const mpc_t op2)
Function: int mpc_cmp_si_si (const mpc_t op1, long int op2r, long int op2i)
Macro: int mpc_cmp_si (mpc_t op1, long int op2)

Compare op1 and op2, where in the case of mpc_cmp_si_si, op2 is taken to be op2r + i op2i. The return value c can be decomposed into x = MPC_INEX_RE(c) and y = MPC_INEX_IM(c), such that x is positive if the real part of op1 is greater than that of op2, zero if both real parts are equal, and negative if the real part of op1 is less than that of op2, and likewise for y. Both op1 and op2 are considered to their full own precision, which may differ. It is not allowed that one of the operands has a NaN (Not-a-Number) part.

The storage of the return value is such that equality can be simply checked with mpc_cmp (op1, op2) == 0.

Function: int mpc_cmp_abs (const mpc_t op1, const mpc_t op2)

Compare the absolute values of op1 and op2. The return value is 0 if both are the same (including infinity), positive if the absolute value of op1 is greater than that of op2, and negative if it is smaller. If op1 or op2 has a real or imaginary part which is NaN, the function behaves like mpfr_cmp on two real numbers of which at least one is NaN.


5.6 Projection and Decomposing Functions

Function: int mpc_real (mpfr_t rop, const mpc_t op, mpfr_rnd_t rnd)

Set rop to the value of the real part of op rounded in the direction rnd.

Function: int mpc_imag (mpfr_t rop, const mpc_t op, mpfr_rnd_t rnd)

Set rop to the value of the imaginary part of op rounded in the direction rnd.

Macro: mpfr_t mpc_realref (mpc_t op)
Macro: mpfr_t mpc_imagref (mpc_t op)

Return a reference to the real part and imaginary part of op, respectively. The mpfr functions can be used on the result of these macros (note that the mpfr_t type is itself a pointer).

Function: int mpc_arg (mpfr_t rop, const mpc_t op, mpfr_rnd_t rnd)

Set rop to the argument of op, with a branch cut along the negative real axis.

Function: int mpc_proj (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Compute a projection of op onto the Riemann sphere. Set rop to op rounded in the direction rnd, except when at least one part of op is infinite (even if the other part is a NaN) in which case the real part of rop is set to plus infinity and its imaginary part to a signed zero with the same sign as the imaginary part of op.


5.7 Basic Arithmetic Functions

All the following functions are designed in such a way that, when working with real numbers instead of complex numbers, their complexity should essentially be the same as with the GNU MPFR library, with only a marginal overhead due to the GNU MPC layer.

Function: int mpc_add (mpc_t rop, const mpc_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_add_ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_add_fr (mpc_t rop, const mpc_t op1, const mpfr_t op2, mpc_rnd_t rnd)

Set rop to op1 + op2 rounded according to rnd.

Function: int mpc_sub (mpc_t rop, const mpc_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_sub_fr (mpc_t rop, const mpc_t op1, const mpfr_t op2, mpc_rnd_t rnd)
Function: int mpc_fr_sub (mpc_t rop, const mpfr_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_sub_ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Macro: int mpc_ui_sub (mpc_t rop, unsigned long int op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_ui_ui_sub (mpc_t rop, unsigned long int re1, unsigned long int im1, mpc_t op2, mpc_rnd_t rnd)

Set rop to op1 - op2 rounded according to rnd. For mpc_ui_ui_sub, op1 is re1 + im1.

Function: int mpc_neg (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to -op rounded according to rnd. Just changes the sign if rop and op are the same variable.

Function: int mpc_sum (mpc_t rop, const mpc_ptr* op, unsigned long n, mpc_rnd_t rnd)

Set rop to the sum of the elements in the array op of length n, rounded according to rnd.

Function: int mpc_mul (mpc_t rop, const mpc_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_mul_ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_mul_si (mpc_t rop, const mpc_t op1, long int op2, mpc_rnd_t rnd)
Function: int mpc_mul_fr (mpc_t rop, const mpc_t op1, const mpfr_t op2, mpc_rnd_t rnd)

Set rop to op1 times op2 rounded according to rnd. Note: for mpc_mul, in case op1 and op2 have the same value, use mpc_sqr for better efficiency.

Function: int mpc_mul_i (mpc_t rop, const mpc_t op, int sgn, mpc_rnd_t rnd)

Set rop to op times the imaginary unit i if sgn is non-negative, set rop to op times -i otherwise, in both cases rounded according to rnd.

Function: int mpc_sqr (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the square of op rounded according to rnd.

Function: int mpc_fma (mpc_t rop, const mpc_t op1, const mpc_t op2, const mpc_t op3, mpc_rnd_t rnd)

Set rop to op1*op2+op3, rounded according to rnd, with only one final rounding.

Function: int mpc_dot (mpc_t rop, const mpc_ptr* op1, mpc_ptr* op2, unsigned long n, mpc_rnd_t rnd)

Set rop to the dot product of the elements in the arrays op1 and op2, both of length n, rounded according to rnd.

Function: int mpc_div (mpc_t rop, const mpc_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_div_ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_div_fr (mpc_t rop, const mpc_t op1, const mpfr_t op2, mpc_rnd_t rnd)
Function: int mpc_ui_div (mpc_t rop, unsigned long int op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_fr_div (mpc_t rop, const mpfr_t op1, const mpc_t op2, mpc_rnd_t rnd)

Set rop to op1/op2 rounded according to rnd.

Function: int mpc_conj (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the conjugate of op rounded according to rnd. Just changes the sign of the imaginary part if rop and op are the same variable.

Function: int mpc_abs (mpfr_t rop, const mpc_t op, mpfr_rnd_t rnd)

Set the floating-point number rop to the absolute value of op, rounded in the direction rnd.

Function: int mpc_norm (mpfr_t rop, const mpc_t op, mpfr_rnd_t rnd)

Set the floating-point number rop to the norm of op (i.e., the square of its absolute value), rounded in the direction rnd.

Function: int mpc_mul_2ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_mul_2si (mpc_t rop, const mpc_t op1, long int op2, mpc_rnd_t rnd)

Set rop to op1 times 2 raised to op2 rounded according to rnd. Just modifies the exponents of the real and imaginary parts by op2 when rop and op1 are identical.

Function: int mpc_div_2ui (mpc_t rop, const mpc_t op1, unsigned long int op2, mpc_rnd_t rnd)
Function: int mpc_div_2si (mpc_t rop, const mpc_t op1, long int op2, mpc_rnd_t rnd)

Set rop to op1 divided by 2 raised to op2 rounded according to rnd. Just modifies the exponents of the real and imaginary parts by op2 when rop and op1 are identical.


5.8 Power Functions and Logarithm

Function: int mpc_sqrt (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the square root of op rounded according to rnd. The returned value rop has a non-negative real part, and if its real part is zero, a non-negative imaginary part.

Function: int mpc_pow (mpc_t rop, const mpc_t op1, const mpc_t op2, mpc_rnd_t rnd)
Function: int mpc_pow_d (mpc_t rop, const mpc_t op1, double op2, mpc_rnd_t rnd)
Function: int mpc_pow_ld (mpc_t rop, const mpc_t op1, long double op2, mpc_rnd_t rnd)
Function: int mpc_pow_si (mpc_t rop, const mpc_t op1, long op2, mpc_rnd_t rnd)
Function: int mpc_pow_ui (mpc_t rop, const mpc_t op1, unsigned long op2, mpc_rnd_t rnd)
Function: int mpc_pow_z (mpc_t rop, const mpc_t op1, const mpz_t op2, mpc_rnd_t rnd)
Function: int mpc_pow_fr (mpc_t rop, const mpc_t op1, const mpfr_t op2, mpc_rnd_t rnd)

Set rop to op1 raised to the power op2, rounded according to rnd. For mpc_pow_d, mpc_pow_ld, mpc_pow_si, mpc_pow_ui, mpc_pow_z and mpc_pow_fr, the imaginary part of op2 is considered as +0. When both op1 and op2 are zero, the result has real part 1, and imaginary part 0, with sign being the opposite of that of op2.

Function: int mpc_exp (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the exponential of op, rounded according to rnd with the precision of rop.

Function: int mpc_log (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_log10 (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the natural and base-10 logarithm of op respectively, rounded according to rnd with the precision of rop. The principal branch is chosen, with the branch cut on the negative real axis, so that the imaginary part of the result lies in ]-Pi , Pi] and ]-Pi/log(10) , Pi/log(10)] respectively.

Function: int mpc_rootofunity (mpc_t rop, unsigned long int n, unsigned long int k, mpc_rnd_t rnd)

Set rop to the standard primitive n-th root of unity raised to the power k, that is, exp (2 Pi i k / n), rounded according to rnd with the precision of rop.


5.9 Trigonometric Functions

Function: int mpc_sin (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_cos (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_tan (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the sine, cosine, tangent of op, rounded according to rnd with the precision of rop.

Function: int mpc_sin_cos (mpc_t rop_sin, mpc_t rop_cos, const mpc_t op, mpc_rnd_t rnd_sin, mpc_rnd_t rnd_cos)

Set rop_sin to the sine of op, rounded according to rnd_sin with the precision of rop_sin, and rop_cos to the cosine of op, rounded according to rnd_cos with the precision of rop_cos.

Function: int mpc_sinh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_cosh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_tanh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the hyperbolic sine, hyperbolic cosine, hyperbolic tangent of op, rounded according to rnd with the precision of rop.

Function: int mpc_asin (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_acos (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_atan (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the inverse sine, inverse cosine, inverse tangent of op, rounded according to rnd with the precision of rop.

Function: int mpc_asinh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_acosh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)
Function: int mpc_atanh (mpc_t rop, const mpc_t op, mpc_rnd_t rnd)

Set rop to the inverse hyperbolic sine, inverse hyperbolic cosine, inverse hyperbolic tangent of op, rounded according to rnd with the precision of rop. The branch cut of mpc_acosh is (-Inf, 1)


5.10 Miscellaneous Functions

Function: int mpc_urandom (mpc_t rop, gmp_randstate_t state)

Generate a uniformly distributed random complex in the unit square [0, 1] x [0, 1]. Return 0, unless an exponent in the real or imaginary part is not in the current exponent range, in which case that part is set to NaN and a zero value is returned. The second argument is a gmp_randstate_t structure which should be created using the GMP rand_init function, see the GMP manual.

Function: const char * mpc_get_version (void)

Return the GNU MPC version, as a null-terminated string.

Macro: MPC_VERSION
Macro: MPC_VERSION_MAJOR
Macro: MPC_VERSION_MINOR
Macro: MPC_VERSION_PATCHLEVEL
Macro: MPC_VERSION_STRING

MPC_VERSION is the version of GNU MPC as a preprocessing constant. MPC_VERSION_MAJOR, MPC_VERSION_MINOR and MPC_VERSION_PATCHLEVEL are respectively the major, minor and patch level of GNU MPC version, as preprocessing constants. MPC_VERSION_STRING is the version as a string constant, which can be compared to the result of mpc_get_version to check at run time the header file and library used match:

if (strcmp (mpc_get_version (), MPC_VERSION_STRING))
  fprintf (stderr, "Warning: header and library do not match\n");

Note: Obtaining different strings is not necessarily an error, as in general, a program compiled with some old GNU MPC version can be dynamically linked with a newer GNU MPC library version (if allowed by the library versioning system).

Macro: long MPC_VERSION_NUM (major, minor, patchlevel)

Create an integer in the same format as used by MPC_VERSION from the given major, minor and patchlevel. Here is an example of how to check the GNU MPC version at compile time:

#if (!defined(MPC_VERSION) || (MPC_VERSION<MPC_VERSION_NUM(2,1,0)))
# error "Wrong GNU MPC version."
#endif

5.11 Advanced Functions

Macro: MPC_SET_X_Y (real_suffix, imag_suffix, rop, real, imag, rnd)

The macro MPC_SET_X_Y is designed to serve as the body of an assignment function and cannot be used by itself. The real_suffix and imag_suffix parameters are the types of the real and imaginary part, that is, the x in the mpfr_set_x function one would use to set the part; for the mpfr type, use fr. real (respectively imag) is the value you want to assign to the real (resp. imaginary) part, its type must conform to real_suffix (resp. imag_suffix). rnd is the mpc_rnd_t rounding mode. The return value is the usual inexact value (see Return Value).

For instance, you can define mpc_set_ui_fr as follows:

int mpc_set_ui_fr (mpc_t rop, unsigned long int re, mpfr_t im, mpc_rnd_t rnd)
    MPC_SET_X_Y (ui, fr, rop, re, im, rnd);

5.12 Internals

These macros and functions are mainly designed for the implementation of GNU MPC, but may be useful for users too. However, no upward compatibility is guaranteed. You need to include mpc-impl.h to use them.

The macro MPC_MAX_PREC(z) gives the maximum of the precisions of the real and imaginary parts of a complex number.


Next: , Previous: , Up: GNU MPC   [Index]