00001 // Copyright (C) 2011 CNRS - Ecole Polytechnique - INRIA. 00002 // 00003 // This file is part of TIFA. 00004 // 00005 // TIFA is free software; you can redistribute it and/or modify it under the 00006 // terms of the GNU Lesser General Public License as published by the Free 00007 // Software Foundation; either version 2.1 of the License, or (at your option) 00008 // any later version. 00009 // 00010 // TIFA is distributed in the hope that it will be useful, but WITHOUT ANY 00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00013 // more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, 00017 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00042 #if !defined(_TIFA_SQRT_CONT_FRAC_H_) 00043 00047 #define _TIFA_SQRT_CONT_FRAC_H_ 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00053 #include <inttypes.h> 00054 #include <gmp.h> 00055 00069 struct struct_cont_frac_state_t { 00070 // 00071 // _NOTE_: In the CFRAC algorithm, we don't need the value of the 00072 // denominator, b. 00073 // 00078 mpz_t a; 00079 // 00080 // The following variable is not needed in the CFRAC algorithm. 00081 // Uncomment this declaration to also compute the denominator b. 00082 // 00083 //mpz_t b; 00087 mpz_t p; 00091 mpz_t q; 00095 mpz_t t; 00100 mpz_t sqrtn; 00105 mpz_t n; 00110 uint32_t nsteps_performed; 00111 // 00112 // "Private" temporary variables. 00113 // These are declared in the structure just to avoid redundant 00114 // initializations and deallocations. 00115 // 00121 mpz_t _ztmp_q_; 00127 mpz_t _ztmp_; 00132 mpz_t _a_old_; 00133 // 00134 // The following variables are not needed in the CFRAC algorithm. 00135 // Uncomment these declarations to also compute the denominator b. 00136 // 00137 //mpz_t _b_old_; 00145 void (*step_function)(struct struct_cont_frac_state_t* const, uint32_t); 00146 }; 00147 00152 typedef struct struct_cont_frac_state_t cont_frac_state_t; 00153 00169 void init_cont_frac_state(cont_frac_state_t* const state, const mpz_t n); 00170 00178 void clear_cont_frac_state(cont_frac_state_t* const state); 00179 00192 inline static void step_cont_frac_state(cont_frac_state_t* const state, 00193 uint32_t nsteps) { 00194 state->step_function(state, nsteps); 00195 } 00196 00197 #ifdef __cplusplus 00198 } 00199 #endif 00200 00201 #endif