1 /* mpc_set_x -- Set the real part of a complex number 2 (imaginary part equals +0 regardless of rounding mode). 3 4 Copyright (C) 2008, 2009, 2010, 2011 INRIA 5 6 This file is part of GNU MPC. 7 8 GNU MPC is free software; you can redistribute it and/or modify it under 9 the terms of the GNU Lesser General Public License as published by the 10 Free Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 13 GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY 14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 16 more details. 17 18 You should have received a copy of the GNU Lesser General Public License 19 along with this program. If not, see http://www.gnu.org/licenses/ . 20 */ 21 22 #include "config.h" 23 24 #ifdef HAVE_INTTYPES_H 25 # include <inttypes.h> /* for intmax_t */ 26 #else 27 # ifdef HAVE_STDINT_H 28 # include <stdint.h> 29 # endif 30 #endif 31 32 #ifdef HAVE_COMPLEX_H 33 # include <complex.h> 34 #endif 35 36 #include "mpc-impl.h" 37 38 #define MPC_SET_X(real_t, z, real_value, rnd) \ 39 { \ 40 int _inex_re, _inex_im; \ 41 _inex_re = (mpfr_set_ ## real_t) (mpc_realref (z), (real_value), MPC_RND_RE (rnd)); \ 42 _inex_im = mpfr_set_ui (mpc_imagref (z), 0, MPC_RND_IM (rnd)); \ 43 return MPC_INEX (_inex_re, _inex_im); \ 44 } 45 46 int 47 mpc_set_fr (mpc_ptr a, mpfr_srcptr b, mpc_rnd_t rnd) 48 MPC_SET_X (fr, a, b, rnd) 49 50 int 51 mpc_set_d (mpc_ptr a, double b, mpc_rnd_t rnd) 52 MPC_SET_X (d, a, b, rnd) 53 54 int 55 mpc_set_ld (mpc_ptr a, long double b, mpc_rnd_t rnd) 56 MPC_SET_X (ld, a, b, rnd) 57 58 int 59 mpc_set_ui (mpc_ptr a, unsigned long int b, mpc_rnd_t rnd) 60 MPC_SET_X (ui, a, b, rnd) 61 62 int 63 mpc_set_si (mpc_ptr a, long int b, mpc_rnd_t rnd) 64 MPC_SET_X (si, a, b, rnd) 65 66 int 67 mpc_set_z (mpc_ptr a, mpz_srcptr b, mpc_rnd_t rnd) 68 MPC_SET_X (z, a, b, rnd) 69 70 int 71 mpc_set_q (mpc_ptr a, mpq_srcptr b, mpc_rnd_t rnd) 72 MPC_SET_X (q, a, b, rnd) 73 74 int 75 mpc_set_f (mpc_ptr a, mpf_srcptr b, mpc_rnd_t rnd) 76 MPC_SET_X (f, a, b, rnd) 77 78 #ifdef _MPC_H_HAVE_INTMAX_T 79 int 80 mpc_set_uj (mpc_ptr a, uintmax_t b, mpc_rnd_t rnd) 81 MPC_SET_X (uj, a, b, rnd) 82 83 int 84 mpc_set_sj (mpc_ptr a, intmax_t b, mpc_rnd_t rnd) 85 MPC_SET_X (sj, a, b, rnd) 86 #endif 87 88 #ifdef HAVE_COMPLEX_H 89 int 90 mpc_set_dc (mpc_ptr a, double _Complex b, mpc_rnd_t rnd) { 91 return mpc_set_d_d (a, creal (b), cimag (b), rnd); 92 } 93 94 int 95 mpc_set_ldc (mpc_ptr a, long double _Complex b, mpc_rnd_t rnd) { 96 return mpc_set_ld_ld (a, creall (b), cimagl (b), rnd); 97 } 98 #endif 99 100 void 101 mpc_set_nan (mpc_ptr a) { 102 mpfr_set_nan (mpc_realref (a)); 103 mpfr_set_nan (mpc_imagref (a)); 104 } 105