1 /* mpfi-impl.h -- Include file for mpfi. 2 3 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2018, 4 Spaces project, Inria Lorraine 5 and Salsa project, INRIA Rocquencourt, 6 and Arenaire project, Inria Rhone-Alpes, France 7 and Lab. ANO, USTL (Univ. of Lille), France 8 9 This file is part of the MPFI Library. 10 11 The MPFI Library is free software; you can redistribute it and/or modify 12 it under the terms of the GNU Lesser General Public License as published by 13 the Free Software Foundation; either version 2.1 of the License, or (at your 14 option) any later version. 15 16 The MPFI Library is distributed in the hope that it will be useful, but 17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 License for more details. 20 21 You should have received a copy of the GNU Lesser General Public License 22 along with the MPFI Library; see the file COPYING.LIB. If not, write to 23 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 24 MA 02110-1301, USA. */ 25 26 #ifndef __MPFI_IMPL_H__ 27 #define __MPFI_IMPL_H__ 28 29 #include "mpfi.h" 30 #include "mpfi_config.h" 31 32 #if MPFR_VERSION < MPFR_VERSION_NUM(3,0,0) 33 #define MPFI_RNDD GMP_RNDD 34 #define MPFI_RNDU GMP_RNDU 35 #else 36 #define MPFI_RNDD MPFR_RNDD 37 #define MPFI_RNDU MPFR_RNDU 38 #define GMP_RNDN MPFR_RNDN 39 #endif 40 41 #define MPFI_IS_POS(x) ((mpfr_sgn((&(x->left)))>=0) && (mpfr_sgn((&(x->right)))>0)) 42 #define MPFI_IS_STRICTLY_POS(x) ((mpfr_sgn((&(x->left)))>0) && (mpfr_sgn((&(x->right)))>0)) 43 #define MPFI_IS_NONNEG(x) ((mpfr_sgn((&(x->left)))>=0) && (mpfr_sgn((&(x->right)))>=0)) 44 #define MPFI_IS_NEG(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))<=0)) 45 #define MPFI_IS_STRICTLY_NEG(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))<0)) 46 #define MPFI_IS_NONPOS(x) ((mpfr_sgn((&(x->left)))<=0) && (mpfr_sgn((&(x->right)))<=0)) 47 #define MPFI_IS_NULL(x) ((mpfr_sgn((&(x->left)))==0) && (mpfr_sgn((&(x->right)))==0)) 48 #define MPFI_HAS_ZERO(x) ((mpfr_sgn((&(x->left)))<0) && (mpfr_sgn((&(x->right)))>0)) 49 #define MPFI_HAS_ZERO_NONSTRICT(x) ((mpfr_sgn((&(x->left)))<=0) && (mpfr_sgn((&(x->right)))>=0)) 50 51 52 #if defined(GMP_NUMB_BITS) /* GMP 4.1.2 or above */ 53 # define BITS_PER_MP_LIMB (GMP_NUMB_BITS+GMP_NAIL_BITS) 54 #elif defined (__GMP_BITS_PER_MP_LIMB) /* Older versions 4.x.x */ 55 #define BITS_PER_MP_LIMB __GMP_BITS_PER_MP_LIMB 56 #else 57 # error "Could not detect BITS_PER_MP_LIMB. Get GMP 4.1.0 at least." 58 #endif 59 60 #define MPFR_RET_NAN do {mpfr_set_nanflag(); return 0;} while (0) 61 62 #define MPFR_IS_NAN(x) (mpfr_nan_p(x)) 63 #define MPFR_IS_ZERO(x) (mpfr_sgn(x) == 0) 64 #define MPFR_IS_INF(x) (mpfr_inf_p(x)) 65 66 /* Internal functions */ 67 68 #if defined (__cplusplus) 69 extern "C" { 70 #endif 71 72 73 74 mpfr_prec_t mpfi_quadrant (mpz_ptr, mpfr_srcptr); 75 int mpfi_cmp_sym_pi (mpz_srcptr, mpfr_srcptr, mpfr_srcptr, mpfr_prec_t); 76 77 /* default comparison functions */ 78 int mpfi_cmp_default (mpfi_srcptr, mpfi_srcptr); 79 int mpfi_cmp_d_default (mpfi_srcptr, const double); 80 int mpfi_cmp_ui_default (mpfi_srcptr, const unsigned long); 81 int mpfi_cmp_si_default (mpfi_srcptr, const long); 82 int mpfi_cmp_z_default (mpfi_srcptr, mpz_srcptr); 83 int mpfi_cmp_q_default (mpfi_srcptr, mpq_srcptr); 84 int mpfi_cmp_fr_default (mpfi_srcptr, mpfr_srcptr); 85 86 int mpfi_is_pos_default (mpfi_srcptr); 87 int mpfi_is_nonneg_default (mpfi_srcptr); 88 int mpfi_is_neg_default (mpfi_srcptr); 89 int mpfi_is_nonpos_default (mpfi_srcptr); 90 int mpfi_is_zero_default (mpfi_srcptr); 91 int mpfi_is_strictly_neg_default (mpfi_srcptr); 92 int mpfi_is_strictly_pos_default (mpfi_srcptr); 93 94 #if defined (__cplusplus) 95 } 96 #endif 97 98 /* Debug macros */ 99 #ifdef WARN_IF_REVERTED_ENDPOINTS 100 /* include stdio.h when using this macro */ 101 # define WARNING_REVERTED_ENDPOINTS(a, fname) \ 102 do { \ 103 fprintf (stdout, "Pb endpoints in reverse order in %s\n", fname); \ 104 mpfi_out_str (stdout, 10, 0, a); \ 105 fprintf (stdout, "\n"); \ 106 } while (0) 107 #else 108 # define WARNING_REVERTED_ENDPOINTS(a, fname) 109 #endif 110 111 #endif /* __MPFI_IMPL_H__ */ 112