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