1/* mpc.h -- Include file for mpc.
2
3Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012, 2014, 2015 INRIA
4
5This file is part of GNU MPC.
6
7GNU MPC is free software; you can redistribute it and/or modify it under
8the terms of the GNU Lesser General Public License as published by the
9Free Software Foundation; either version 3 of the License, or (at your
10option) any later version.
11
12GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with this program. If not, see http://www.gnu.org/licenses/ .
19*/
20
21#ifndef __MPC_H
22#define __MPC_H
23
24#include "gmp.h"
25#include "mpfr.h"
26
27/* Backwards compatibility with mpfr<3.0.0 */
28#ifndef mpfr_exp_t
29#define mpfr_exp_t mp_exp_t
30#endif
31
32/* Define MPC version number */
33#define MPC_VERSION_MAJOR 1
34#define MPC_VERSION_MINOR 0
35#define MPC_VERSION_PATCHLEVEL 3
36#define MPC_VERSION_STRING "1.0.3"
37
38/* Macros dealing with MPC VERSION */
39#define MPC_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
40#define MPC_VERSION \
41 MPC_VERSION_NUM(MPC_VERSION_MAJOR,MPC_VERSION_MINOR,MPC_VERSION_PATCHLEVEL)
42
43/* Check if stdint.h/inttypes.h is included */
44#if defined (INTMAX_C) && defined (UINTMAX_C)
45#define _MPC_H_HAVE_INTMAX_T 1
46#endif
47
48/* Return values */
49
50/* Transform negative to 2, positive to 1, leave 0 unchanged */
51#define MPC_INEX_POS(inex) (((inex) < 0) ? 2 : ((inex) == 0) ? 0 : 1)
52/* Transform 2 to negative, 1 to positive, leave 0 unchanged */
53#define MPC_INEX_NEG(inex) (((inex) == 2) ? -1 : ((inex) == 0) ? 0 : 1)
54
55/* The global inexact flag is made of (real flag) + 4 * (imaginary flag), where
56 each of the real and imaginary inexact flag are:
57 0 when the result is exact (no rounding error)
58 1 when the result is larger than the exact value
59 2 when the result is smaller than the exact value */
60#define MPC_INEX(inex_re, inex_im) \
61 (MPC_INEX_POS(inex_re) | (MPC_INEX_POS(inex_im) << 2))
62#define MPC_INEX_RE(inex) MPC_INEX_NEG((inex) & 3)
63#define MPC_INEX_IM(inex) MPC_INEX_NEG((inex) >> 2)
64
65/* For functions computing two results, the return value is
66 inexact1+16*inexact2, which is 0 iif both results are exact. */
67#define MPC_INEX12(inex1, inex2) (inex1 | (inex2 << 4))
68#define MPC_INEX1(inex) (inex & 15)
69#define MPC_INEX2(inex) (inex >> 4)
70
71/* Definition of rounding modes */
72
73/* a complex rounding mode is just a pair of two real rounding modes
74 we reserve four bits for a real rounding mode. */
75typedef int mpc_rnd_t;
76
77#define MPC_RND(r1,r2) (((int)(r1)) + ((int)(r2) << 4))
78#define MPC_RND_RE(x) ((mpfr_rnd_t)((x) & 0x0F))
79#define MPC_RND_IM(x) ((mpfr_rnd_t)((x) >> 4))
80
81#define MPC_RNDNN MPC_RND (GMP_RNDN,GMP_RNDN)
82#define MPC_RNDNZ MPC_RND (GMP_RNDN,GMP_RNDZ)
83#define MPC_RNDNU MPC_RND (GMP_RNDN,GMP_RNDU)
84#define MPC_RNDND MPC_RND (GMP_RNDN,GMP_RNDD)
85
86#define MPC_RNDZN MPC_RND (GMP_RNDZ,GMP_RNDN)
87#define MPC_RNDZZ MPC_RND (GMP_RNDZ,GMP_RNDZ)
88#define MPC_RNDZU MPC_RND (GMP_RNDZ,GMP_RNDU)
89#define MPC_RNDZD MPC_RND (GMP_RNDZ,GMP_RNDD)
90
91#define MPC_RNDUN MPC_RND (GMP_RNDU,GMP_RNDN)
92#define MPC_RNDUZ MPC_RND (GMP_RNDU,GMP_RNDZ)
93#define MPC_RNDUU MPC_RND (GMP_RNDU,GMP_RNDU)
94#define MPC_RNDUD MPC_RND (GMP_RNDU,GMP_RNDD)
95
96#define MPC_RNDDN MPC_RND (GMP_RNDD,GMP_RNDN)
97#define MPC_RNDDZ MPC_RND (GMP_RNDD,GMP_RNDZ)
98#define MPC_RNDDU MPC_RND (GMP_RNDD,GMP_RNDU)
99#define MPC_RNDDD MPC_RND (GMP_RNDD,GMP_RNDD)
100
101
102/* Definitions of types and their semantics */
103
104typedef struct {
105 mpfr_t re;
106 mpfr_t im;
107}
108__mpc_struct;
109
110typedef __mpc_struct mpc_t[1];
111typedef __mpc_struct *mpc_ptr;
112typedef const __mpc_struct *mpc_srcptr;
113
114/* Support for WINDOWS DLL, see
115 http://lists.gforge.inria.fr/pipermail/mpc-discuss/2011-November/000990.html;
116 when building the DLL, export symbols, otherwise behave as GMP */
117#if defined (__MPC_LIBRARY_BUILD) && __GMP_LIBGMP_DLL
118#define __MPC_DECLSPEC __GMP_DECLSPEC_EXPORT
119#else
120#define __MPC_DECLSPEC __GMP_DECLSPEC
121#endif
122
123#if defined (__cplusplus)
124extern "C" {
125#endif
126
127__MPC_DECLSPEC int mpc_add (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
128__MPC_DECLSPEC int mpc_add_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
129__MPC_DECLSPEC int mpc_add_si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
130__MPC_DECLSPEC int mpc_add_ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
131__MPC_DECLSPEC int mpc_sub (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
132__MPC_DECLSPEC int mpc_sub_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
133__MPC_DECLSPEC int mpc_fr_sub (mpc_ptr, mpfr_srcptr, mpc_srcptr, mpc_rnd_t);
134__MPC_DECLSPEC int mpc_sub_ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
135__MPC_DECLSPEC int mpc_ui_ui_sub (mpc_ptr, unsigned long int, unsigned long int, mpc_srcptr, mpc_rnd_t);
136__MPC_DECLSPEC int mpc_mul (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
137__MPC_DECLSPEC int mpc_mul_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
138__MPC_DECLSPEC int mpc_mul_ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
139__MPC_DECLSPEC int mpc_mul_si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
140__MPC_DECLSPEC int mpc_mul_i (mpc_ptr, mpc_srcptr, int, mpc_rnd_t);
141__MPC_DECLSPEC int mpc_sqr (mpc_ptr, mpc_srcptr, mpc_rnd_t);
142__MPC_DECLSPEC int mpc_div (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
143__MPC_DECLSPEC int mpc_pow (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
144__MPC_DECLSPEC int mpc_pow_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
145__MPC_DECLSPEC int mpc_pow_ld (mpc_ptr, mpc_srcptr, long double, mpc_rnd_t);
146__MPC_DECLSPEC int mpc_pow_d (mpc_ptr, mpc_srcptr, double, mpc_rnd_t);
147__MPC_DECLSPEC int mpc_pow_si (mpc_ptr, mpc_srcptr, long, mpc_rnd_t);
148__MPC_DECLSPEC int mpc_pow_ui (mpc_ptr, mpc_srcptr, unsigned long, mpc_rnd_t);
149__MPC_DECLSPEC int mpc_pow_z (mpc_ptr, mpc_srcptr, mpz_srcptr, mpc_rnd_t);
150__MPC_DECLSPEC int mpc_div_fr (mpc_ptr, mpc_srcptr, mpfr_srcptr, mpc_rnd_t);
151__MPC_DECLSPEC int mpc_fr_div (mpc_ptr, mpfr_srcptr, mpc_srcptr, mpc_rnd_t);
152__MPC_DECLSPEC int mpc_div_ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
153__MPC_DECLSPEC int mpc_ui_div (mpc_ptr, unsigned long int, mpc_srcptr, mpc_rnd_t);
154__MPC_DECLSPEC int mpc_div_2ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
155__MPC_DECLSPEC int mpc_mul_2ui (mpc_ptr, mpc_srcptr, unsigned long int, mpc_rnd_t);
156__MPC_DECLSPEC int mpc_div_2si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
157__MPC_DECLSPEC int mpc_mul_2si (mpc_ptr, mpc_srcptr, long int, mpc_rnd_t);
158__MPC_DECLSPEC int mpc_conj (mpc_ptr, mpc_srcptr, mpc_rnd_t);
159__MPC_DECLSPEC int mpc_neg (mpc_ptr, mpc_srcptr, mpc_rnd_t);
160__MPC_DECLSPEC int mpc_norm (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
161__MPC_DECLSPEC int mpc_abs (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
162__MPC_DECLSPEC int mpc_sqrt (mpc_ptr, mpc_srcptr, mpc_rnd_t);
163__MPC_DECLSPEC int mpc_set (mpc_ptr, mpc_srcptr, mpc_rnd_t);
164__MPC_DECLSPEC int mpc_set_d (mpc_ptr, double, mpc_rnd_t);
165__MPC_DECLSPEC int mpc_set_d_d (mpc_ptr, double, double, mpc_rnd_t);
166__MPC_DECLSPEC int mpc_set_ld (mpc_ptr, long double, mpc_rnd_t);
167__MPC_DECLSPEC int mpc_set_ld_ld (mpc_ptr, long double, long double, mpc_rnd_t);
168__MPC_DECLSPEC int mpc_set_f (mpc_ptr, mpf_srcptr, mpc_rnd_t);
169__MPC_DECLSPEC int mpc_set_f_f (mpc_ptr, mpf_srcptr, mpf_srcptr, mpc_rnd_t);
170__MPC_DECLSPEC int mpc_set_fr (mpc_ptr, mpfr_srcptr, mpc_rnd_t);
171__MPC_DECLSPEC int mpc_set_fr_fr (mpc_ptr, mpfr_srcptr, mpfr_srcptr, mpc_rnd_t);
172__MPC_DECLSPEC int mpc_set_q (mpc_ptr, mpq_srcptr, mpc_rnd_t);
173__MPC_DECLSPEC int mpc_set_q_q (mpc_ptr, mpq_srcptr, mpq_srcptr, mpc_rnd_t);
174__MPC_DECLSPEC int mpc_set_si (mpc_ptr, long int, mpc_rnd_t);
175__MPC_DECLSPEC int mpc_set_si_si (mpc_ptr, long int, long int, mpc_rnd_t);
176__MPC_DECLSPEC int mpc_set_ui (mpc_ptr, unsigned long int, mpc_rnd_t);
177__MPC_DECLSPEC int mpc_set_ui_ui (mpc_ptr, unsigned long int, unsigned long int, mpc_rnd_t);
178__MPC_DECLSPEC int mpc_set_z (mpc_ptr, mpz_srcptr, mpc_rnd_t);
179__MPC_DECLSPEC int mpc_set_z_z (mpc_ptr, mpz_srcptr, mpz_srcptr, mpc_rnd_t);
180__MPC_DECLSPEC void mpc_swap (mpc_ptr, mpc_ptr);
181__MPC_DECLSPEC int mpc_fma (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
182
183__MPC_DECLSPEC void mpc_set_nan (mpc_ptr);
184
185__MPC_DECLSPEC int mpc_real (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
186__MPC_DECLSPEC int mpc_imag (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
187__MPC_DECLSPEC int mpc_arg (mpfr_ptr, mpc_srcptr, mpfr_rnd_t);
188__MPC_DECLSPEC int mpc_proj (mpc_ptr, mpc_srcptr, mpc_rnd_t);
189__MPC_DECLSPEC int mpc_cmp (mpc_srcptr, mpc_srcptr);
190__MPC_DECLSPEC int mpc_cmp_si_si (mpc_srcptr, long int, long int);
191__MPC_DECLSPEC int mpc_exp (mpc_ptr, mpc_srcptr, mpc_rnd_t);
192__MPC_DECLSPEC int mpc_log (mpc_ptr, mpc_srcptr, mpc_rnd_t);
193__MPC_DECLSPEC int mpc_log10 (mpc_ptr, mpc_srcptr, mpc_rnd_t);
194__MPC_DECLSPEC int mpc_sin (mpc_ptr, mpc_srcptr, mpc_rnd_t);
195__MPC_DECLSPEC int mpc_cos (mpc_ptr, mpc_srcptr, mpc_rnd_t);
196__MPC_DECLSPEC int mpc_sin_cos (mpc_ptr, mpc_ptr, mpc_srcptr, mpc_rnd_t, mpc_rnd_t);
197__MPC_DECLSPEC int mpc_tan (mpc_ptr, mpc_srcptr, mpc_rnd_t);
198__MPC_DECLSPEC int mpc_sinh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
199__MPC_DECLSPEC int mpc_cosh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
200__MPC_DECLSPEC int mpc_tanh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
201__MPC_DECLSPEC int mpc_asin (mpc_ptr, mpc_srcptr, mpc_rnd_t);
202__MPC_DECLSPEC int mpc_acos (mpc_ptr, mpc_srcptr, mpc_rnd_t);
203__MPC_DECLSPEC int mpc_atan (mpc_ptr, mpc_srcptr, mpc_rnd_t);
204__MPC_DECLSPEC int mpc_asinh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
205__MPC_DECLSPEC int mpc_acosh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
206__MPC_DECLSPEC int mpc_atanh (mpc_ptr, mpc_srcptr, mpc_rnd_t);
207__MPC_DECLSPEC void mpc_clear (mpc_ptr);
208__MPC_DECLSPEC int mpc_urandom (mpc_ptr, gmp_randstate_t);
209__MPC_DECLSPEC void mpc_init2 (mpc_ptr, mpfr_prec_t);
210__MPC_DECLSPEC void mpc_init3 (mpc_ptr, mpfr_prec_t, mpfr_prec_t);
211__MPC_DECLSPEC mpfr_prec_t mpc_get_prec (mpc_srcptr x);
212__MPC_DECLSPEC void mpc_get_prec2 (mpfr_prec_t *pr, mpfr_prec_t *pi, mpc_srcptr x);
213__MPC_DECLSPEC void mpc_set_prec (mpc_ptr, mpfr_prec_t);
214__MPC_DECLSPEC const char * mpc_get_version (void);
215
216__MPC_DECLSPEC int mpc_strtoc (mpc_ptr, const char *, char **, int, mpc_rnd_t);
217__MPC_DECLSPEC int mpc_set_str (mpc_ptr, const char *, int, mpc_rnd_t);
218__MPC_DECLSPEC char * mpc_get_str (int, size_t, mpc_srcptr, mpc_rnd_t);
219__MPC_DECLSPEC void mpc_free_str (char *);
220
221/* declare certain functions only if appropriate headers have been included */
222#ifdef _MPC_H_HAVE_INTMAX_T
223__MPC_DECLSPEC int mpc_set_sj (mpc_ptr, intmax_t, mpc_rnd_t);
224__MPC_DECLSPEC int mpc_set_uj (mpc_ptr, uintmax_t, mpc_rnd_t);
225__MPC_DECLSPEC int mpc_set_sj_sj (mpc_ptr, intmax_t, intmax_t, mpc_rnd_t);
226__MPC_DECLSPEC int mpc_set_uj_uj (mpc_ptr, uintmax_t, uintmax_t, mpc_rnd_t);
227#endif
228
229#ifdef _Complex_I
230__MPC_DECLSPEC int mpc_set_dc (mpc_ptr, double _Complex, mpc_rnd_t);
231__MPC_DECLSPEC int mpc_set_ldc (mpc_ptr, long double _Complex, mpc_rnd_t);
232__MPC_DECLSPEC double _Complex mpc_get_dc (mpc_srcptr, mpc_rnd_t);
233__MPC_DECLSPEC long double _Complex mpc_get_ldc (mpc_srcptr, mpc_rnd_t);
234#endif
235
236#ifdef _GMP_H_HAVE_FILE
237__MPC_DECLSPEC int mpc_inp_str (mpc_ptr, FILE *, size_t *, int, mpc_rnd_t);
238__MPC_DECLSPEC size_t mpc_out_str (FILE *, int, size_t, mpc_srcptr, mpc_rnd_t);
239#endif
240
241#if defined (__cplusplus)
242}
243#endif
244
245#define mpc_realref(x) ((x)->re)
246#define mpc_imagref(x) ((x)->im)
247
248#define mpc_cmp_si(x, y) \
249 ( mpc_cmp_si_si ((x), (y), 0l) )
250#define mpc_ui_sub(x, y, z, r) mpc_ui_ui_sub (x, y, 0ul, z, r)
251
252/*
253 Define a fake mpfr_set_fr so that, for instance, mpc_set_fr_z would
254 be defined as follows:
255 mpc_set_fr_z (mpc_t rop, mpfr_t x, mpz_t y, mpc_rnd_t rnd)
256 MPC_SET_X_Y (fr, z, rop, x, y, rnd)
257*/
258#ifndef mpfr_set_fr
259#define mpfr_set_fr mpfr_set
260#endif
261#define MPC_SET_X_Y(real_t, imag_t, z, real_value, imag_value, rnd) \
262 { \
263 int _inex_re, _inex_im; \
264 _inex_re = (mpfr_set_ ## real_t) (mpc_realref (z), (real_value), MPC_RND_RE (rnd)); \
265 _inex_im = (mpfr_set_ ## imag_t) (mpc_imagref (z), (imag_value), MPC_RND_IM (rnd)); \
266 return MPC_INEX (_inex_re, _inex_im); \
267 }
268
269#endif /* ifndef __MPC_H */
270