deleted packaging
[platform/upstream/mpc.git] / doc / mpc.texi
1 \input texinfo
2 @setfilename mpc.info
3 @include version.texi
4 @settitle GNU MPC @value{VERSION}
5 @synindex tp fn
6
7 @set MINGMP 4.3.2
8 @set MINMPFR 2.4.2
9
10 @set AUTHORS Andreas Enge, Philippe Th@'eveny, Paul Zimmermann
11
12 @copying
13 This manual is for GNU MPC, a library for multiple precision complex arithmetic,
14 version @value{VERSION} of @value{UPDATED-MONTH}.
15
16 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 INRIA
17
18 @quotation
19 Permission is granted to copy, distribute and/or modify this document
20 under the terms of the GNU Free Documentation License, Version 1.3 or
21 any later version published by the Free Software Foundation; with no
22 Invariant Sections. A copy of the license is included in the section
23 entitled ``GNU Free Documentation License.''
24 @end quotation
25 @end copying
26
27 @iftex
28 @afourpaper
29 @end iftex
30 @tex
31 \global\parindent=0pt
32 \global\parskip=8pt
33 \global\baselineskip=13pt
34 @end tex
35
36 @dircategory GNU Packages
37 @direntry
38 * mpc: (mpc)Multiple Precision Complex Library.
39 @end direntry
40
41
42 @titlepage
43 @title GNU MPC
44 @subtitle The GNU Multiple Precision Complex Library
45 @subtitle Edition @value{VERSION}
46 @subtitle @value{UPDATED-MONTH}
47 @author @value{AUTHORS}
48 @page
49 @vskip 0pt plus 1filll
50 @insertcopying
51 @end titlepage
52
53
54 @ifnottex
55 @node Top
56 @top GNU MPC
57
58 This manual documents how to install and use the GNU Multiple Precision
59 Complex Library, version @value{VERSION}
60 @end ifnottex
61
62 @menu
63 * Copying::                     GNU MPC Copying Conditions (LGPL).
64 * Introduction to GNU MPC::         Brief introduction to GNU MPC.
65 * Installing GNU MPC::              How to configure and compile the GNU MPC library.
66 * Reporting Bugs::              How to usefully report bugs.
67 * GNU MPC Basics::                  What every GNU MPC user should know.
68 * Complex Functions::           Functions for arithmetic on complex numbers.
69 * References::
70 * Concept Index::
71 * Function Index::
72 * GNU Free Documentation License::
73 @end menu
74
75 @c  @times{} made available as a "x" in info and html (already works in tex).
76 @ifnottex
77 @macro times
78 x
79 @end macro
80 @end ifnottex
81
82
83 @node Copying
84 @unnumbered GNU MPC Copying Conditions
85 @cindex Copying conditions
86 @cindex Conditions for copying GNU MPC
87
88 GNU MPC is free software; you can redistribute it and/or modify it under
89 the terms of the GNU Lesser General Public License as published by the
90 Free Software Foundation; either version 3 of the License, or (at your
91 option) any later version.
92
93 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
94 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
95 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
96 more details.
97
98 You should have received a copy of the GNU Lesser General Public License
99 along with this program. If not, see @uref{http://www.gnu.org/licenses/}.
100
101
102 @node Introduction to GNU MPC
103 @chapter Introduction to GNU MPC
104
105
106 GNU MPC is a portable library written in C for arbitrary precision arithmetic
107 on complex numbers providing correct rounding. It implements a multiprecision
108 equivalent of the C99 standard.
109 It builds upon the GNU MP and the GNU MPFR libraries.
110
111 @section How to use this Manual
112
113 Everyone should read @ref{GNU MPC Basics}.  If you need to install the library
114 yourself, you need to read @ref{Installing GNU MPC}, too.
115
116 The remainder of the manual can be used for later reference, although it is
117 probably a good idea to skim through it.
118
119 @node Installing GNU MPC
120 @chapter Installing GNU MPC
121 @cindex Installation
122
123 To build GNU MPC, you first have to install GNU MP (version @value{MINGMP} or higher) and
124 GNU MPFR (version @value{MINMPFR} or higher) on your computer.  You need a C compiler;
125 GCC version 4.4 or higher is recommended, since GNU MPC may trigger a bug in previous
126 versions, see the thread at
127 @uref{http://lists.gforge.inria.fr/pipermail/mpc-discuss/2011-February/000823.html}.
128 And you need a
129 standard Unix @samp{make} program, plus some other standard Unix utility
130 programs.
131
132 Here are the steps needed to install the library on Unix systems:
133
134 @enumerate
135 @item
136 @samp{tar xzf mpc-@value{VERSION}.tar.gz}
137
138 @item
139 @samp{cd mpc-@value{VERSION}}
140
141 @item
142 @samp{./configure}
143
144 if GMP and GNU MPFR are installed into standard directories, that is, directories
145 that are searched by default by the compiler and the linking tools.
146
147 @samp{./configure --with-gmp=<gmp_install_dir>}
148
149 is used to indicate a different location where GMP is
150 installed. Alternatively, you can specify directly GMP include and GMP lib
151 directories with @samp{./configure --with-gmp-lib=<gmp_lib_dir>
152 --with-gmp-include=<gmp_include_dir>}.
153
154 @samp{./configure --with-mpfr=<mpfr_install_dir>}
155
156 is used to indicate a different location where GNU MPFR is
157 installed. Alternatively, you can specify directly GNU MPFR include and GNU MPFR lib
158 directories with @samp{./configure --with-mpf-lib=<mpfr_lib_dir>
159 --with-mpfr-include=<mpfr_include_dir>}.
160
161 Another useful parameter is @samp{--prefix}, which can be used to
162 specify an alternative installation location instead of
163 @file{/usr/local}; see @samp{make install} below.
164
165 To enable checking for memory leaks using @command{valgrind} during
166 @code{make check}, add the parameter @code{--enable-valgrind-tests}.
167
168 If for debugging purposes you wish to log calls to GNU MPC functions from
169 within your code, add the parameter @samp{--enable-logging}.
170 In your code, replace the inclusion of @file{mpc.h} by @file{mpc-log.h}
171 and link the executable dynamically.
172 Then all calls to functions with only complex arguments are printed to
173 @file{stderr} in the following form: First, the function name is given,
174 followed by its type such as @samp{c_cc}, meaning that the function has
175 one complex result (one @samp{c} in front of the @samp{_}), computed from
176 two complex arguments (two @samp{c} after the @samp{_}). Then, the
177 precisions of the real and the imaginary part of the first result is given,
178 followed by the second one and so on. Finally, for each argument, the
179 precisions of its real and imaginary part are specified and the argument
180 itself is printed in hexadecimal via the function
181 @code{mpc_out_str}
182 (@pxref{String and Stream Input and Output}).
183 The option requires a dynamic library, so it may not be combined with
184 @code{--disable-shared}.
185
186 Use @samp{./configure --help} for an exhaustive list of parameters.
187
188 @item
189 @samp{make}
190
191 This compiles GNU MPC in the working directory.
192
193 @item
194 @samp{make check}
195
196 This will make sure GNU MPC was built correctly.
197
198 If you get error messages, please report them to
199 @samp{mpc-discuss@@lists.gforge.inria.fr} (@xref{Reporting Bugs}, for
200 information on what to include in useful bug reports).
201
202 @item
203 @samp{make install}
204
205 This will copy the file @file{mpc.h} to the directory
206 @file{/usr/local/include}, the file @file{libmpc.a} to the directory
207 @file{/usr/local/lib}, and the file @file{mpc.info} to the directory
208 @file{/usr/local/share/info} (or if you passed the @samp{--prefix} option to
209 @file{configure}, using the prefix directory given as argument to
210 @samp{--prefix} instead of @file{/usr/local}). Note: you need write permissions
211 on these directories.
212
213 @end enumerate
214
215
216 @section Other `make' Targets
217
218 There are some other useful make targets:
219
220 @itemize @bullet
221 @item
222 @samp{info}
223
224 Create an info version of the manual, in @file{mpc.info}.
225
226 @item
227 @samp{pdf}
228
229 Create a PDF version of the manual, in @file{doc/mpc.pdf}.
230
231 @item
232 @samp{dvi}
233
234 Create a DVI version of the manual, in @file{doc/mpc.dvi}.
235
236 @item
237 @samp{ps}
238
239 Create a Postscript version of the manual, in @file{doc/mpc.ps}.
240
241 @item
242 @samp{html}
243
244 Create an HTML version of the manual, in several pages in the
245 directory @file{doc/mpc.html}; if you want only one output HTML file,
246 then type @samp{makeinfo --html --no-split mpc.texi} instead.
247
248 @item
249 @samp{clean}
250
251 Delete all object files and archive files, but not the configuration files.
252
253 @item
254 @samp{distclean}
255
256 Delete all files not included in the distribution.
257
258 @item
259 @samp{uninstall}
260
261 Delete all files copied by @samp{make install}.
262 @end itemize
263
264
265
266 @section Known Build Problems
267
268 On AIX, if GMP was built with the 64-bit ABI, before building and testing GNU MPC,
269 it might be necessary to set the @samp{OBJECT_MODE} environment variable to 64
270 by, e.g.,
271
272 @samp{export OBJECT_MODE=64}
273
274 This has been tested with the C compiler IBM XL C/C++ Enterprise Edition
275 V8.0 for AIX, version: 08.00.0000.0021, GMP 4.2.4 and GNU MPFR 2.4.1.
276
277 Please report any other problems you encounter to
278 @samp{mpc-discuss@@lists.gforge.inria.fr}.
279 @xref{Reporting Bugs}.
280
281 @node Reporting Bugs
282 @chapter Reporting Bugs
283 @cindex Reporting bugs
284
285 If you think you have found a bug in the GNU MPC library,
286 please investigate
287 and report it. We have made this library available to you, and it is not to ask
288 too much from you, to ask you to report the bugs that you find.
289
290 There are a few things you should think about when you put your bug report
291 together.
292
293 You have to send us a test case that makes it possible for us to reproduce the
294 bug.  Include instructions on how to run the test case.
295
296 You also have to explain what is wrong; if you get a crash, or if the results
297 printed are incorrect and in that case, in what way.
298
299 Please include compiler version information in your bug report.
300 This can be extracted using @samp{gcc -v},
301 or @samp{cc -V} on some machines.
302 Also, include the output from @samp{uname -a}.
303
304 If your bug report is good, we will do our best to help you to get a corrected
305 version of the library; if the bug report is poor, we will not do anything about
306 it (aside of chiding you to send better bug reports).
307
308 Send your bug report to: @samp{mpc-discuss@@lists.gforge.inria.fr}.
309
310 If you think something in this manual is unclear, or downright incorrect, or if
311 the language needs to be improved, please send a note to the same address.
312
313 @node GNU MPC Basics
314 @chapter GNU MPC Basics
315
316
317 @cindex @file{mpc.h}
318 All declarations needed to use GNU MPC are collected in the include file
319 @file{mpc.h}.  It is designed to work with both C and C++ compilers.
320 You should include that file in any program using the GNU MPC library
321 by adding the line
322 @example
323    #include "mpc.h"
324 @end example
325
326 @section Nomenclature and Types
327
328 @cindex Complex number
329 @tindex @code{mpc_t}
330 @noindent
331 @dfn{Complex number} or @dfn{Complex} for short, is a pair of two
332 arbitrary precision floating-point numbers (for the real and imaginary parts).
333 The C data type for such objects is @code{mpc_t}.
334
335 @cindex Precision
336 @tindex @code{mpfr_prec_t}
337 @noindent
338 The @dfn{Precision} is the number of bits used to represent the mantissa
339 of the real and imaginary parts;
340 the corresponding C data type is @code{mpfr_prec_t}.
341 For more details on the allowed precision range,
342 @ifinfo
343 @pxref{Nomenclature and Types,,, mpfr.info,GNU MPFR}.
344 @end ifinfo
345 @ifnotinfo
346 see Section ``Nomenclature and Types'' in @cite{GNU MPFR}.
347 @end ifnotinfo
348
349 @cindex Rounding Mode
350 @tindex @code{mpc_rnd_t}
351 @noindent
352 The @dfn{rounding mode} specifies the way to round the result of a
353 complex operation, in case the exact result can not be represented
354 exactly in the destination mantissa;
355 the corresponding C data type is @code{mpc_rnd_t}.
356 A complex rounding mode is a pair of two rounding modes: one for the real
357 part, one for the imaginary part.
358
359 @section Function Classes
360
361 There is only one class of functions in the GNU MPC library, namely functions for
362 complex arithmetic. The function names begin with @code{mpc_}. The
363 associated type is @code{mpc_t}.
364
365
366 @section GNU MPC Variable Conventions
367
368 As a general rule, all GNU MPC functions expect output arguments before input
369 arguments.  This notation is based on an analogy with the assignment operator.
370
371 GNU MPC allows you to use the same variable for both input and output in the same
372 expression.  For example, the main function for floating-point multiplication,
373 @code{mpc_mul}, can be used like this: @code{mpc_mul (x, x, x, rnd_mode)}.
374 This
375 computes the square of @var{x} with rounding mode @code{rnd_mode}
376 and puts the result back in @var{x}.
377
378 Before you can assign to an GNU MPC variable, you need to initialize it by calling
379 one of the special initialization functions.  When you are done with a
380 variable, you need to clear it out, using one of the functions for that
381 purpose.
382
383 A variable should only be initialized once, or at least cleared out between
384 each initialization.  After a variable has been initialized, it may be
385 assigned to any number of times.
386
387 For efficiency reasons, avoid to initialize and clear out a variable in loops.
388 Instead, initialize it before entering the loop, and clear it out after the
389 loop has exited.
390
391 You do not need to be concerned about allocating additional space for GNU MPC
392 variables, since each of its real and imaginary part
393 has a mantissa of fixed size.
394 Hence unless you change its precision, or clear and reinitialize it,
395 a complex variable will have the same allocated space during all its
396 life.
397
398
399 @section Rounding Modes
400
401 A complex rounding mode is of the form @code{MPC_RNDxy} where
402 @code{x} and @code{y} are one of @code{N} (to nearest), @code{Z} (towards
403 zero), @code{U} (towards plus infinity), @code{D} (towards minus infinity).
404 The first letter refers to the rounding mode for the real part,
405 and the second one for the imaginary part.
406 For example @code{MPC_RNDZU} indicates to round the real part towards zero,
407 and the imaginary part towards plus infinity.
408
409 The @samp{round to nearest} mode works as in the IEEE P754 standard: in case
410 the number to be rounded lies exactly in the middle of two representable
411 numbers, it is rounded to the one with the least significant bit set to zero.
412 For example, the number 5, which is represented by (101) in binary, is rounded
413 to (100)=4 with a precision of two bits, and not to (110)=6.
414
415
416 @anchor{return-value}
417 @section Return Value
418
419 Most GNU MPC functions have a return value of type @code{int}, which is used
420 to indicate the position of the rounded real and imaginary parts with respect
421 to the exact (infinite precision) values.
422 If this integer is @code{i}, the macros @code{MPC_INEX_RE(i)} and
423 @code{MPC_INEX_IM(i)} give 0 if the corresponding rounded value is exact,
424 a negative value if the rounded value is less than the exact one,
425 and a positive value if it is greater than the exact one.
426 Similarly, functions computing a result of type @code{mpfr_t}
427 return an integer that is 0, positive or negative depending on
428 whether the rounded value is the same, larger or smaller then
429 the exact result.
430
431 Some functions, such as @code{mpc_sin_cos}, compute two complex results;
432 the macros @code{MPC_INEX1(i)} and @code{MPC_INEX2(i)}, applied to
433 the return value @code{i} of such a function, yield the exactness value
434 corresponding to the first or the second computed value, respectively.
435
436
437 @section Branch Cuts And Special Values
438
439 Some complex functions have branch cuts, across which the function is
440 discontinous. In GNU MPC, the branch cuts chosen are the same as those
441 specified for the corresponding functions in the ISO C99 standard.
442
443 Likewise, when evaluated at a point whose real or imaginary part is
444 either infinite or a NaN or a signed zero, a function returns the same
445 value as those specified for the corresponding function in the ISO C99
446 standard.
447
448
449 @node Complex Functions
450 @chapter Complex Functions
451 @cindex Complex functions
452
453 The complex functions expect arguments of type @code{mpc_t}.
454
455 The GNU MPC floating-point functions have an interface that is similar to the
456 GNU MP
457 integer functions.  The function prefix for operations on complex numbers is
458 @code{mpc_}.
459
460 @cindex User-defined precision
461 The precision of a computation is defined as follows: Compute the requested
462 operation exactly (with ``infinite precision''), and round the result to
463 the destination variable precision with the given rounding mode.
464
465 The GNU MPC complex functions are intended to be a smooth extension
466 of the IEEE P754 arithmetic. The results obtained on one
467 computer should not differ from the results obtained on a computer with a
468 different word size.
469
470
471 @menu
472 * Initializing Complex Numbers::
473 * Assigning Complex Numbers::
474 * Converting Complex Numbers::
475 * String and Stream Input and Output::
476 * Complex Comparison::
477 * Projection & Decomposing::
478 * Basic Arithmetic::
479 * Power Functions and Logarithm::
480 * Trigonometric Functions::
481 * Miscellaneous Complex Functions::
482 * Advanced Functions::
483 * Internals::
484 @end menu
485
486 @node Initializing Complex Numbers
487 @section Initialization Functions
488
489 An @code{mpc_t} object must be initialized before storing the first value in
490 it.  The functions @code{mpc_init2} and @code{mpc_init3}
491 are used for that purpose.
492
493 @deftypefun void mpc_init2 (mpc_t @var{z}, mpfr_prec_t @var{prec})
494 Initialize @var{z} to precision @var{prec} bits
495 and set its real and imaginary parts to NaN.
496 Normally, a variable should be initialized once only
497 or at least be cleared, using @code{mpc_clear}, between initializations.
498 @end deftypefun
499
500 @deftypefun void mpc_init3 (mpc_t @var{z}, mpfr_prec_t @var{prec_r}, mpfr_prec_t @var{prec_i})
501 Initialize @var{z} with the precision of its real part being
502 @var{prec_r} bits and the precision of its imaginary part being
503 @var{prec_i} bits, and set the real and imaginary parts to NaN.
504 @end deftypefun
505
506 @deftypefun void mpc_clear (mpc_t @var{z})
507 Free the space occupied by @var{z}.  Make sure to call this function for all
508 @code{mpc_t} variables when you are done with them.
509 @end deftypefun
510
511 @need 2000
512 Here is an example on how to initialize complex variables:
513 @example
514 @{
515   mpc_t x, y;
516   mpc_init2 (x, 256);           /* precision @emph{exactly} 256 bits */
517   mpc_init3 (y, 100, 50);       /* 100/50 bits for the real/imaginary part */
518   @dots{}
519   mpc_clear (x);
520   mpc_clear (y);
521 @}
522 @end example
523
524 The following function is useful for changing the precision during a
525 calculation.  A typical use would be for adjusting the precision gradually in
526 iterative algorithms like Newton-Raphson, making the computation precision
527 closely match the actual accurate part of the numbers.
528
529 @deftypefun void mpc_set_prec (mpc_t @var{x}, mpfr_prec_t @var{prec})
530 Reset the precision of @var{x} to be @strong{exactly} @var{prec} bits,
531 and set its real/imaginary parts to NaN.
532 The previous value stored in @var{x} is lost. It is equivalent to
533 a call to @code{mpc_clear(x)} followed by a call to
534 @code{mpc_init2(x, prec)}, but more efficient as no allocation is done in
535 case the current allocated space for the mantissa of @var{x} is sufficient.
536 @end deftypefun
537
538 @deftypefun mpfr_prec_t mpc_get_prec (mpc_t @var{x})
539 If the real and imaginary part of @var{x} have the same precision, it is returned,
540 otherwise, 0 is returned.
541 @end deftypefun
542
543 @deftypefun void mpc_get_prec2 (mpfr_prec_t* @var{pr}, mpfr_prec_t* @var{pi}, mpc_t @var{x})
544 Returns the precision of the real part of @var{x} via @var{pr} and of its imaginary part
545 via @var{pi}.
546 @end deftypefun
547
548
549 @node Assigning Complex Numbers
550 @section Assignment Functions
551 @cindex Complex assignment functions
552
553 These functions assign new values to already initialized complex numbers
554 (@pxref{Initializing Complex Numbers}).
555 When using any functions with @code{intmax_t} or @code{uintmax_t}
556 parameters, you must include
557 @code{<stdint.h>} or @code{<inttypes.h>} @emph{before} @file{mpc.h}, to allow
558 @file{mpc.h} to define prototypes for these functions.
559 Similarly, functions with parameters of type @code{complex} or
560 @code{long complex} are defined only if @code{<complex.h>} is included
561 @emph{before} @file{mpc.h}.
562 If you need assignment functions that are not in the current API, you can
563 define them using the @code{MPC_SET_X_Y} macro (@pxref{Advanced Functions}).
564
565 @deftypefun int mpc_set (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
566 Set the value of @var{rop} from @var{op}, rounded to the precision of @var{rop}
567 with the given rounding mode @var{rnd}.
568 @end deftypefun
569
570 @deftypefun int mpc_set_ui (mpc_t @var{rop}, unsigned long int @var{op}, mpc_rnd_t @var{rnd})
571 @deftypefunx int mpc_set_si (mpc_t @var{rop}, long int @var{op}, mpc_rnd_t @var{rnd})
572 @deftypefunx int mpc_set_uj (mpc_t @var{rop}, uintmax_t @var{op}, mpc_rnd_t @var{rnd})
573 @deftypefunx int mpc_set_sj (mpc_t @var{rop}, intmax_t @var{op}, mpc_rnd_t @var{rnd})
574 @deftypefunx int mpc_set_d (mpc_t @var{rop}, double @var{op}, mpc_rnd_t @var{rnd})
575 @deftypefunx int mpc_set_ld (mpc_t @var{rop}, long double @var{op}, mpc_rnd_t @var{rnd})
576 @deftypefunx int mpc_set_dc (mpc_t @var{rop}, double _Complex @var{op}, mpc_rnd_t @var{rnd})
577 @deftypefunx int mpc_set_ldc (mpc_t @var{rop}, long double _Complex @var{op}, mpc_rnd_t @var{rnd})
578 @deftypefunx int mpc_set_z (mpc_t @var{rop}, mpz_t @var{op} mpc_rnd_t @var{rnd})
579 @deftypefunx int mpc_set_q (mpc_t @var{rop}, mpq_t @var{op} mpc_rnd_t @var{rnd})
580 @deftypefunx int mpc_set_f (mpc_t @var{rop}, mpf_t @var{op} mpc_rnd_t @var{rnd})
581 @deftypefunx int mpc_set_fr (mpc_t @var{rop}, mpfr_t @var{op}, mpc_rnd_t @var{rnd})
582 Set the value of @var{rop} from @var{op}, rounded to the precision of
583 @var{rop} with the given rounding mode @var{rnd}.
584 The argument @var{op} is interpreted as real, so the imaginary part of
585 @var{rop} is set to zero with a positive sign.
586 Please note that even a @code{long int} may have to be rounded, if the
587 destination precision is less than the machine word width.
588 For @code{mpc_set_d}, be careful that the input number @var{op} may not be
589 exactly representable as a double-precision number (this happens for 0.1 for
590 instance), in which case it is first rounded by the C compiler to a
591 double-precision number, and then only to a complex number.
592 @end deftypefun
593
594 @deftypefun int mpc_set_ui_ui (mpc_t @var{rop}, unsigned long int @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
595 @deftypefunx int mpc_set_si_si (mpc_t @var{rop}, long int @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
596 @deftypefunx int mpc_set_uj_uj (mpc_t @var{rop}, uintmax_t @var{op1}, uintmax_t @var{op2}, mpc_rnd_t @var{rnd})
597 @deftypefunx int mpc_set_sj_sj (mpc_t @var{rop}, intmax_t @var{op1}, intmax_t @var{op2}, mpc_rnd_t @var{rnd})
598 @deftypefunx int mpc_set_d_d (mpc_t @var{rop}, double @var{op1}, double @var{op2}, mpc_rnd_t @var{rnd})
599 @deftypefunx int mpc_set_ld_ld (mpc_t @var{rop}, long double @var{op1}, long double @var{op2}, mpc_rnd_t @var{rnd})
600 @deftypefunx int mpc_set_z_z (mpc_t @var{rop}, mpz_t @var{op1}, mpz_t @var{op2}, mpc_rnd_t @var{rnd})
601 @deftypefunx int mpc_set_q_q (mpc_t @var{rop}, mpq_t @var{op1}, mpq_t @var{op2}, mpc_rnd_t @var{rnd})
602 @deftypefunx int mpc_set_f_f (mpc_t @var{rop}, mpf_t @var{op1}, mpf_t @var{op2}, mpc_rnd_t @var{rnd})
603 @deftypefunx int mpc_set_fr_fr (mpc_t @var{rop}, mpfr_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
604 Set the real part of @var{rop} from @var{op1}, and its imaginary part from
605 @var{op2}, according to the rounding mode @var{rnd}.
606
607 Beware that the behaviour of @code{mpc_set_fr_fr} is undefined if @var{op1}
608 or @var{op2} is a pointer to the real or imaginary part of @var{rop}.
609 To exchange the real and the imaginary part of a complex number, either use
610 @code{mpfr_swap (mpc_realref (rop), mpc_imagref (rop))}, which also exchanges
611 the precisions of the two parts; or use a temporary variable.
612 @end deftypefun
613
614 For functions assigning complex variables from strings or input streams,
615 @pxref{String and Stream Input and Output}.
616
617 @deftypefun void mpc_set_nan (mpc_t @var{rop})
618 Set @var{rop} to Nan+i*NaN.
619 @end deftypefun
620
621 @deftypefun void mpc_swap (mpc_t @var{op1}, mpc_t @var{op2})
622 Swap the values of @var{op1} and @var{op2} efficiently. Warning: The
623 precisions are exchanged, too; in case these are different,
624 @code{mpc_swap} is thus not equivalent to three @code{mpc_set} calls using a
625 third auxiliary variable.
626 @end deftypefun
627
628
629 @node Converting Complex Numbers
630 @section Conversion Functions
631 @cindex Conversion functions
632
633 The following functions are available only if @code{<complex.h>}
634 is included @emph{before} @file{mpc.h}.
635
636 @deftypefun double _Complex mpc_get_dc (mpc_t @var{op}, mpc_rnd_t @var{rnd})
637 @deftypefunx {long double _Complex} mpc_get_ldc (mpc_t @var{op}, mpc_rnd_t @var{rnd})
638 Convert @var{op} to a C complex number, using the rounding mode @var{rnd}.
639 @end deftypefun
640
641
642 For functions converting complex variables to strings or stream output,
643 @pxref{String and Stream Input and Output}.
644
645
646 @node String and Stream Input and Output
647 @section String and Stream Input and Output
648 @cindex String and stream input and output
649
650 @deftypefun int mpc_strtoc (mpc_t @var{rop}, const char *@var{nptr}, char **@var{endptr}, int @var{base}, mpc_rnd_t @var{rnd})
651 Read a complex number from a string @var{nptr} in base @var{base}, rounded to
652 the precision of @var{rop} with the given rounding mode @var{rnd}.
653 The @var{base} must be either 0 or a number from 2 to 36 (otherwise the
654 behaviour is undefined).
655 If @var{nptr} starts with valid data, the result is stored in @var{rop},
656 the usual inexact value is returned (@pxref{return-value,, Return
657 Value}) and, if @var{endptr} is not the null pointer,
658 @var{*endptr} points to the character just after the valid data.
659 Otherwise, @var{rop} is set to @code{NaN + i * NaN}, -1 is returned and,
660 if @var{endptr} is not the null pointer,
661 the value of @var{nptr} is stored in the location referenced by
662 @var{endptr}.
663
664 The expected form of a complex number string is either a real number (an
665 optional leading whitespace, an optional sign followed by a floating-point
666 number), or a pair of real numbers in parentheses separated by whitespace. If
667 a real number is read, the missing imaginary part is set to +0.
668 The form of a floating-point number depends on the base and is described
669 in the documentation of @code{mpfr_strtofr}
670 @ifinfo
671 (@pxref{Assignment Functions,,, mpfr.info,GNU MPFR}).
672 @end ifinfo
673 @ifnotinfo
674 in the GNU MPFR manual.
675 @end ifnotinfo
676 For instance, @code{"3.1415926"}, @code{"(1.25e+7 +.17)"}, @code{"(@@nan@@
677 2)"} and @code{"(-0 -7)"} are valid strings for @var{base} = 10.
678 If @var{base} = 0, then a prefix may be used to indicate the base in which the
679 floating-point number is written. Use prefix '0b' for binary numbers, prefix
680 '0x' for hexadecimal numbers, and no prefix for decimal numbers.
681 The real and imaginary part may then be written in different bases.
682 For instance, @code{"(1.024e+3 +2.05e+3)"} and @code{"(0b1p+10 +0x802)"} are
683 valid strings for @code{base}=0 and represent the same value.
684 @end deftypefun
685
686 @deftypefun int mpc_set_str (mpc_t @var{rop}, const char *@var{s}, int @var{base}, mpc_rnd_t rnd)
687 Set @var{rop} to the value of the string @var{s} in base @var{base}, rounded
688 to the precision of @var{rop} with the given rounding mode @var{rnd}.
689 See the documentation of @code{mpc_strtoc} for a detailed description of the
690 valid string formats.
691 Contrarily to @code{mpc_strtoc}, @code{mpc_set_str} requires the @emph{whole}
692 string to represent a valid complex number (potentially followed by
693 additional white space).
694 This function returns the usual inexact value (@pxref{return-value,, Return
695 Value}) if the entire string up to the final null character is a valid number
696 in base @var{base}; otherwise it returns @minus{}1, and @var{rop} is set to
697 NaN+i*NaN.
698 @end deftypefun
699
700 @deftypefun {char *} mpc_get_str (int @var{b}, size_t @var{n}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
701 Convert @var{op} to a string containing its real and imaginary parts,
702 separated by a space and enclosed in a pair of parentheses.
703 The numbers are written in base @var{b} (which may vary from 2 to 36) and
704 rounded according to @var{rnd}. The number of significant digits, at least 2,
705 is given by @var{n}. It is also possible to let
706 @var{n} be zero, in which case the number of digits is chosen large
707 enough so that re-reading the printed value with the same precision, assuming
708 both output and input use rounding to nearest, will recover the original value
709 of @var{op}.
710 Note that @code{mpc_get_str} uses the decimal point of the current locale
711 if available, and @samp{.} otherwise.
712
713 The string is generated using the current memory allocation function
714 (@code{malloc} by default, unless it has been modified using the custom
715 memory allocation interface of @code{gmp}); once it is not needed any more,
716 it should be freed by calling @code{mpc_free_str}.
717 @end deftypefun
718
719 @deftypefun {void} mpc_free_str (char *@var{str})
720 Free the string @var{str}, which needs to have been allocated by
721 a call to @code{mpc_get_str}.
722 @end deftypefun
723
724 The following two functions read numbers from input streams and write
725 them to output streams.
726 When using any of these functions, you need to include @file{stdio.h}
727 @emph{before} @file{mpc.h}.
728
729 @deftypefun int mpc_inp_str (mpc_t @var{rop}, FILE *@var{stream}, size_t *@var{read}, int @var{base}, mpc_rnd_t @var{rnd})
730 Input a string in base @var{base} in the same format as for @code{mpc_strtoc}
731 from stdio stream @var{stream}, rounded according to @var{rnd}, and put the
732 read complex number into @var{rop}.
733 If @var{stream} is the null pointer, @var{rop} is read from @code{stdin}.
734 Return the usual inexact value; if an error occurs, set @var{rop} to @code{NaN
735 + i * NaN} and return -1.
736 If @var{read} is not the null pointer, it is set to the number of read
737 characters.
738
739 Unlike @code{mpc_strtoc}, the function @code{mpc_inp_str} does not possess
740 perfect knowledge of the string to transform and has to read it
741 character by character, so it behaves slightly differently: It tries
742 to read a string describing a complex number and processes this string
743 through a call to @code{mpc_set_str}. Precisely, after skipping optional
744 whitespace, a minimal string is read according to the regular expression
745 @code{mpfr | '(' \s* mpfr \s+ mpfr \s* ')'}, where @code{\s} denotes a whitespace,
746 and @code{mpfr} is either a string containing neither whitespaces nor
747 parentheses, or @code{nan(n-char-sequence)} or @code{@@nan@@(n-char-sequence)}
748 (regardless of capitalisation) with @code{n-char-sequence} a string
749 of ascii letters, digits or @code{'_'}.
750
751 For instance, upon input of @code{"nan(13 1)"}, the function
752 @code{mpc_inp_str} starts to recognise a value of NaN followed by an
753 n-char-sequence indicated by the opening parenthesis; as soon as the
754 space is reached, it becocmes clear that the expression in parentheses
755 is not an n-char-sequence, and the error flag -1 is returned after 6
756 characters have been consumed from the stream (the whitespace itself
757 remaining in the stream).
758 The function @code{mpc_strtoc}, on the other hand, may track back
759 when reaching the whitespace; it treats the string as the two successive
760 complex numbers @code{NaN + i * 0} and @code{13 + i}.
761 It is thus recommended to have a whitespace follow each floating point number
762 to avoid this problem.
763 @end deftypefun
764
765 @deftypefun size_t mpc_out_str (FILE *@var{stream}, int @var{base}, size_t @var{n_digits}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
766 Output @var{op} on stdio stream @var{stream} in
767 base @var{base}, rounded according to @var{rnd}, in the same format
768 as for @code{mpc_strtoc}
769 If @var{stream} is the null pointer, @var{rop} is written to @code{stdout}.
770
771 Return the number of characters written.
772 @end deftypefun
773
774
775 @node Complex Comparison
776 @section Comparison Functions
777 @cindex Complex comparisons functions
778 @cindex Comparison functions
779
780 @deftypefn Function int mpc_cmp (mpc_t @var{op1}, mpc_t @var{op2})
781 @deftypefnx Function int mpc_cmp_si_si (mpc_t @var{op1}, long int @var{op2r}, long int @var{op2i})
782 @deftypefnx Macro int mpc_cmp_si (mpc_t @var{op1}, long int @var{op2})
783
784 Compare @var{op1} and @var{op2}, where in the case of @code{mpc_cmp_si_si},
785 @var{op2} is taken to be @var{op2r} + i @var{op2i}.
786 The return value @var{c} can be decomposed into @code{x = MPC_INEX_RE(c)}
787 and @code{y = MPC_INEX_IM(c)}, such that @var{x} is
788 positive if the real part of @var{op1} is greater than that of @var{op2},
789 zero if both real parts are equal, and negative if the real part of @var{op1}
790 is less than that of @var{op2}, and likewise for @var{y}.
791 Both @var{op1} and @var{op2} are considered to their full own precision,
792 which may differ.
793 It is not allowed that one of the operands has a NaN (Not-a-Number) part.
794
795 The storage of the return value is such that equality can be simply checked
796 with @code{mpc_cmp (op1, op2) == 0}.
797 @end deftypefn
798
799
800 @node Projection & Decomposing
801 @section Projection and Decomposing Functions
802 @cindex Projection and Decomposing Functions
803
804 @deftypefn Function int mpc_real (mpfr_t @var{rop}, mpc_t @var{op}, mpfr_rnd_t @var{rnd})
805 Set @var{rop} to the value of the real part of @var{op} rounded
806 in the direction @var{rnd}.
807 @end deftypefn
808
809 @deftypefn Function int mpc_imag (mpfr_t @var{rop}, mpc_t @var{op}, mpfr_rnd_t @var{rnd})
810 Set @var{rop} to the value of the imaginary part of @var{op} rounded in the
811 direction @var{rnd}.
812 @end deftypefn
813
814 @deftypefn Macro mpfr_t mpc_realref (mpc_t @var{op})
815 @deftypefnx Macro mpfr_t mpc_imagref (mpc_t @var{op})
816 Return a reference to the real part and imaginary part of @var{op},
817 respectively. The @code{mpfr} functions can be used on the result of these
818 macros (note that the @code{mpfr_t} type is itself a pointer).
819 @end deftypefn
820
821 @deftypefn Function int mpc_arg (mpfr_t @var{rop}, mpc_t @var{op}, mpfr_rnd_t @var{rnd})
822 Set @var{rop} to the argument of @var{op}, with a branch cut along the
823 negative real axis.
824 @end deftypefn
825
826 @deftypefn Function int mpc_proj (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
827 Compute a projection of @var{op} onto the Riemann sphere. Set @var{rop} to
828 @var{op} rounded in the direction @var{rnd}, except when at least one part of
829 @var{op} is infinite (even if the other part is a NaN) in which case the real
830 part of @var{rop} is set to plus infinity and its imaginary part to a signed
831 zero with the same sign as the imaginary part of @var{op}.
832 @end deftypefn
833
834
835 @node Basic Arithmetic
836 @section Basic Arithmetic Functions
837 @cindex Complex arithmetic functions
838 @cindex Arithmetic functions
839
840 All the following functions are designed in such a way that, when working
841 with real numbers instead of complex numbers, their complexity should
842 essentially be the same as with the GNU MPFR library, with only a marginal
843 overhead due to the GNU MPC layer.
844
845 @deftypefun int mpc_add (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
846 @deftypefunx int mpc_add_ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
847 @deftypefunx int mpc_add_fr (mpc_t @var{rop}, mpc_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
848 Set @var{rop} to @var{op1} @math{+} @var{op2} rounded according to @var{rnd}.
849 @end deftypefun
850
851 @deftypefn Function int mpc_sub (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
852 @deftypefnx Function int mpc_sub_fr (mpc_t @var{rop}, mpc_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
853 @deftypefnx Function int mpc_fr_sub (mpc_t @var{rop}, mpfr_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
854 @deftypefnx Function int mpc_sub_ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
855 @deftypefnx Macro int mpc_ui_sub (mpc_t @var{rop}, unsigned long int @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
856 @deftypefnx Function int mpc_ui_ui_sub (mpc_t @var{rop}, unsigned long int @var{re1}, unsigned long int @var{im1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
857 Set @var{rop} to @var{op1} @minus{} @var{op2} rounded according to @var{rnd}.
858 For @code{mpc_ui_ui_sub}, @var{op1} is @var{re1} + @var{im1}.
859 @end deftypefn
860
861 @deftypefun int mpc_neg (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
862 Set @var{rop} to @minus{}@var{op} rounded according to @var{rnd}.
863 Just changes the sign if @var{rop} and @var{op} are the same variable.
864 @end deftypefun
865
866 @deftypefun int mpc_mul (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
867 @deftypefunx int mpc_mul_ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
868 @deftypefunx int mpc_mul_si (mpc_t @var{rop}, mpc_t @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
869 @deftypefunx int mpc_mul_fr (mpc_t @var{rop}, mpc_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
870 Set @var{rop} to @var{op1} times @var{op2} rounded according to @var{rnd}.
871 Note: for @code{mpc_mul}, in case @var{op1} and @var{op2} have the same value,
872 use @code{mpc_sqr} for better efficiency.
873 @end deftypefun
874
875 @deftypefun int mpc_mul_i (mpc_t @var{rop}, mpc_t @var{op}, int @var{sgn}, mpc_rnd_t @var{rnd})
876 Set @var{rop} to @var{op} times the imaginary unit i if @var{sgn} is
877 non-negative, set @var{rop} to @var{op} times -i otherwise,
878 in both cases rounded according to @var{rnd}.
879 @end deftypefun
880
881 @deftypefun int mpc_sqr (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
882 Set @var{rop} to the square of @var{op} rounded according to @var{rnd}.
883 @end deftypefun
884
885 @deftypefun int mpc_fma (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_t @var{op3}, mpc_rnd_t @var{rnd})
886 Set @var{rop} to @var{op1}*@var{op2}+@var{op3},
887 rounded according to @var{rnd}, with only one final rounding.
888 @end deftypefun
889
890 @deftypefun int mpc_div (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
891 @deftypefunx int mpc_div_ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
892 @deftypefunx int mpc_div_fr (mpc_t @var{rop}, mpc_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
893 @deftypefunx int mpc_ui_div (mpc_t @var{rop}, unsigned long int @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
894 @deftypefunx int mpc_fr_div (mpc_t @var{rop}, mpfr_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
895 Set @var{rop} to @var{op1}/@var{op2} rounded according to @var{rnd}.
896 @end deftypefun
897
898 @deftypefun int mpc_conj (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
899 Set @var{rop} to the conjugate of @var{op} rounded according to @var{rnd}.
900 Just changes the sign of the imaginary part
901 if @var{rop} and @var{op} are the same variable.
902 @end deftypefun
903
904 @deftypefun int mpc_abs (mpfr_t @var{rop}, mpc_t @var{op}, mpfr_rnd_t @var{rnd})
905 Set the floating-point number @var{rop} to the absolute value of @var{op},
906 rounded in the direction @var{rnd}.
907 @end deftypefun
908
909 @deftypefun int mpc_norm (mpfr_t @var{rop}, mpc_t @var{op}, mpfr_rnd_t @var{rnd})
910 Set the floating-point number @var{rop} to the norm of @var{op}
911 (i.e., the square of its absolute value),
912 rounded in the direction @var{rnd}.
913 @end deftypefun
914
915 @deftypefun int mpc_mul_2ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
916 @deftypefunx int mpc_mul_2si (mpc_t @var{rop}, mpc_t @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
917 Set @var{rop} to @var{op1} times 2 raised to @var{op2}
918 rounded according to @var{rnd}. Just modifies the exponents
919 of the real and imaginary parts by @var{op2}
920 when @var{rop} and @var{op1} are identical.
921 @end deftypefun
922
923 @deftypefun int mpc_div_2ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long int @var{op2}, mpc_rnd_t @var{rnd})
924 @deftypefunx int mpc_div_2ui (mpc_t @var{rop}, mpc_t @var{op1}, long int @var{op2}, mpc_rnd_t @var{rnd})
925 Set @var{rop} to @var{op1} divided by 2 raised to @var{op2}
926 rounded according to @var{rnd}. Just modifies the exponents
927 of the real and imaginary parts by @var{op2}
928 when @var{rop} and @var{op1} are identical.
929 @end deftypefun
930
931
932 @node Power Functions and Logarithm
933 @section Power Functions and Logarithm
934 @cindex Power functions
935 @cindex Logarithm
936
937 @deftypefun int mpc_sqrt (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
938 Set @var{rop} to the square root of @var{op} rounded according to @var{rnd}.
939 The returned value @var{rop} has a non-negative real part, and if its real
940 part is zero, a non-negative imaginary part.
941 @end deftypefun
942
943 @deftypefun int mpc_pow (mpc_t @var{rop}, mpc_t @var{op1}, mpc_t @var{op2}, mpc_rnd_t @var{rnd})
944 @deftypefunx int mpc_pow_d (mpc_t @var{rop}, mpc_t @var{op1}, double @var{op2}, mpc_rnd_t @var{rnd})
945 @deftypefunx int mpc_pow_ld (mpc_t @var{rop}, mpc_t @var{op1}, long double @var{op2}, mpc_rnd_t @var{rnd})
946 @deftypefunx int mpc_pow_si (mpc_t @var{rop}, mpc_t @var{op1}, long @var{op2}, mpc_rnd_t @var{rnd})
947 @deftypefunx int mpc_pow_ui (mpc_t @var{rop}, mpc_t @var{op1}, unsigned long @var{op2}, mpc_rnd_t @var{rnd})
948 @deftypefunx int mpc_pow_z (mpc_t @var{rop}, mpc_t @var{op1}, mpz_t @var{op2}, mpc_rnd_t @var{rnd})
949 @deftypefunx int mpc_pow_fr (mpc_t @var{rop}, mpc_t @var{op1}, mpfr_t @var{op2}, mpc_rnd_t @var{rnd})
950 Set @var{rop} to @var{op1} raised to the power @var{op2}, rounded according
951 to @var{rnd}.
952 For @code{mpc_pow_d}, @code{mpc_pow_ld}, @code{mpc_pow_si}, @code{mpc_pow_ui},
953 @code{mpc_pow_z} and @code{mpc_pow_fr},
954 the imaginary part of @var{op2} is considered as +0.
955 When both @var{op1} and @var{op2} are zero, the result has real part 1,
956 and imaginary part 0, with sign being the opposite of that of @var{op2}.
957 @end deftypefun
958
959 @deftypefun int mpc_exp (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
960 Set @var{rop} to the exponential of @var{op},
961 rounded according to @var{rnd} with the precision of @var{rop}.
962 @end deftypefun
963
964 @deftypefun int mpc_log (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
965 @deftypefunx int mpc_log10 (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
966 Set @var{rop} to the natural and base-10 logarithm of @var{op} respectively,
967 rounded according to @var{rnd} with the precision of @var{rop}.
968 The principal branch is chosen, with the branch cut on the negative real axis,
969 so that the imaginary part of the result lies in
970 @math{]-\pi , \pi]} and @math{]-\pi/log(10) , \pi/log(10)]} respectively.
971 @end deftypefun
972
973
974 @node Trigonometric Functions
975 @section Trigonometric Functions
976 @cindex Trigonometric functions
977
978 @deftypefun int mpc_sin (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
979 Set @var{rop} to the sine of @var{op},
980 rounded according to @var{rnd} with the precision of @var{rop}.
981 @end deftypefun
982
983 @deftypefun int mpc_cos (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
984 Set @var{rop} to the cosine of @var{op},
985 rounded according to @var{rnd} with the precision of @var{rop}.
986 @end deftypefun
987
988 @deftypefun int mpc_sin_cos (mpc_t @var{rop_sin}, mpc_t @var{rop_cos}, mpc_t @var{op}, mpc_rnd_t @var{rnd_sin}, mpc_rnd_t @var{rnd_cos})
989 Set @var{rop_sin} to the sine of @var{op},
990 rounded according to @var{rnd_sin} with the precision of @var{rop_sin},
991 and @var{rop_cos} to the cosine of @var{op},
992 rounded according to @var{rnd_cos} with the precision of @var{rop_cos}.
993 @end deftypefun
994
995 @deftypefun int mpc_tan (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
996 Set @var{rop} to the tangent of @var{op},
997 rounded according to @var{rnd} with the precision of @var{rop}.
998 @end deftypefun
999
1000 @deftypefun int mpc_sinh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1001 Set @var{rop} to the hyperbolic sine of @var{op},
1002 rounded according to @var{rnd} with the precision of @var{rop}.
1003 @end deftypefun
1004
1005 @deftypefun int mpc_cosh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1006 Set @var{rop} to the hyperbolic cosine of @var{op},
1007 rounded according to @var{rnd} with the precision of @var{rop}.
1008 @end deftypefun
1009
1010 @deftypefun int mpc_tanh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1011 Set @var{rop} to the hyperbolic tangent of @var{op},
1012 rounded according to @var{rnd} with the precision of @var{rop}.
1013 @end deftypefun
1014
1015 @deftypefun int mpc_asin (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1016 @deftypefunx int mpc_acos (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1017 @deftypefunx int mpc_atan (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1018 Set @var{rop} to the inverse sine, inverse cosine, inverse tangent of @var{op},
1019 rounded according to @var{rnd} with the precision of @var{rop}.
1020 @end deftypefun
1021
1022 @deftypefun int mpc_asinh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1023 @deftypefunx int mpc_acosh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1024 @deftypefunx int mpc_atanh (mpc_t @var{rop}, mpc_t @var{op}, mpc_rnd_t @var{rnd})
1025 Set @var{rop} to the inverse hyperbolic sine, inverse hyperbolic cosine,
1026 inverse hyperbolic tangent of @var{op},
1027 rounded according to @var{rnd} with the precision of @var{rop}.
1028 The branch cut of @var{mpc_acosh} is @math{(-\infty, 1)}.
1029 @end deftypefun
1030
1031 @node Miscellaneous Complex Functions
1032 @section Miscellaneous Functions
1033 @cindex Miscellaneous complex functions
1034
1035 @deftypefun int mpc_urandom (mpc_t @var{rop}, gmp_randstate_t @var{state})
1036 Generate a uniformly distributed random complex in the unit square @math{[0,
1037 1] @times [0, 1]}. Return 0, unless an exponent in the real or imaginary part
1038 is not in the current exponent range, in which case that part is set to NaN
1039 and a zero value is returned. The second argument is a @code{gmp_randstate_t}
1040 structure which should be created using the GMP @code{rand_init} function, see
1041 the GMP manual.
1042 @end deftypefun
1043
1044 @deftypefun {const char *} mpc_get_version (void)
1045 Return the GNU MPC version, as a null-terminated string.
1046 @end deftypefun
1047
1048 @defmac MPC_VERSION
1049 @defmacx MPC_VERSION_MAJOR
1050 @defmacx MPC_VERSION_MINOR
1051 @defmacx MPC_VERSION_PATCHLEVEL
1052 @defmacx MPC_VERSION_STRING
1053 @code{MPC_VERSION} is the version of GNU MPC as a preprocessing constant.
1054 @code{MPC_VERSION_MAJOR}, @code{MPC_VERSION_MINOR} and
1055 @code{MPC_VERSION_PATCHLEVEL} are respectively the major, minor and
1056 patch level of GNU MPC version, as preprocessing constants.
1057 @code{MPC_VERSION_STRING} is the version as a string constant, which
1058 can be compared to the result of @code{mpc_get_version} to check at
1059 run time the header file and library used match:
1060 @example
1061 if (strcmp (mpc_get_version (), MPC_VERSION_STRING))
1062   fprintf (stderr, "Warning: header and library do not match\n");
1063 @end example
1064 Note: Obtaining different strings is not necessarily an error, as in
1065 general, a program compiled with some old GNU MPC version can be
1066 dynamically linked with a newer GNU MPC library version (if allowed by the
1067 library versioning system).
1068 @end defmac
1069
1070 @deftypefn Macro long MPC_VERSION_NUM (@var{major}, @var{minor}, @var{patchlevel})
1071 Create an integer in the same format as used by @code{MPC_VERSION} from the
1072 given @var{major}, @var{minor} and @var{patchlevel}.
1073 Here is an example of how to check the GNU MPC version at compile time:
1074 @example
1075 #if (!defined(MPC_VERSION) || (MPC_VERSION<MPC_VERSION_NUM(2,1,0)))
1076 # error "Wrong GNU MPC version."
1077 #endif
1078 @end example
1079 @end deftypefn
1080
1081 @node Advanced Functions
1082 @section Advanced Functions
1083
1084 @defmac MPC_SET_X_Y (@var{real_suffix}, @var{imag_suffix}, @var{rop}, @var{real}, @var{imag}, @var{rnd})
1085 The macro MPC_SET_X_Y is designed to serve as the body of an assignment
1086 function and cannot be used by itself.
1087 The @var{real_suffix} and @var{imag_suffix} parameters are the
1088 types of the real and imaginary part, that is, the @code{x} in the
1089 @code{mpfr_set_x} function one would use to set the part;
1090 for the mpfr type, use @code{fr}.
1091 @var{real} (respectively @var{imag}) is the value you want to assign to the
1092 real (resp. imaginary) part, its type must conform to @var{real_suffix}
1093 (resp. @var{imag_suffix}).
1094 @var{rnd} is the @code{mpc_rnd_t} rounding mode.
1095 The return value is the usual inexact value (@pxref{return-value,, Return
1096 Value}).
1097
1098 For instance, you can define mpc_set_ui_fr as follows:
1099 @example
1100 int mpc_set_ui_fr (mpc_t rop, long int re, double im, mpc_rnd_t rnd)
1101     MPC_SET_X_Y (ui, fr, rop, re, im, rnd);
1102 @end example
1103 @end defmac
1104
1105
1106 @node Internals
1107 @section Internals
1108
1109 These macros and
1110 functions are mainly designed for the implementation of GNU MPC,
1111 but may be useful for users too.
1112 However, no upward compatibility is guaranteed.
1113 You need to include @code{mpc-impl.h} to use them.
1114
1115 The macro @code{MPC_MAX_PREC(z)} gives the maximum of the precisions
1116 of the real and imaginary parts of a complex number.
1117
1118
1119 @node References
1120 @unnumbered References
1121
1122 @itemize @bullet
1123
1124 @item
1125 Torbj@"orn Granlund et al.
1126 @code{gmp} -- GNU multiprecision library.
1127 Version 4.2.4, @url{http://gmplib.org/}.
1128
1129 @item
1130 Guillaume Hanrot, Vincent Lef@`evre, Patrick P@'elissier, Paul Zimmermann et al.
1131 @code{mpfr} -- A library for multiple-precision floating-point computations with exact rounding.
1132 Version 2.4.1, @url{http://www.mpfr.org}.
1133
1134 @item
1135 IEEE standard for binary floating-point arithmetic, Technical Report
1136 ANSI-IEEE Standard 754-1985, New York, 1985.
1137 Approved March 21, 1985: IEEE Standards Board; approved July 26,
1138   1985: American National Standards Institute, 18 pages.
1139
1140 @item
1141 Donald E. Knuth, "The Art of Computer Programming", vol 2,
1142 "Seminumerical Algorithms", 2nd edition, Addison-Wesley, 1981.
1143
1144 @item
1145 ISO/IEC 9899:1999, Programming languages — C.
1146
1147 @end itemize
1148
1149 @node Concept Index
1150 @unnumbered Concept Index
1151 @printindex cp
1152
1153 @node Function Index
1154 @unnumbered Function Index
1155 @printindex fn
1156
1157 @node GNU Free Documentation License
1158 @appendix GNU Free Documentation License
1159 @include fdl-1.3.texi
1160
1161 @ifnothtml
1162 @contents
1163 @end ifnothtml
1164
1165 @bye