Main Page   Data Structures   File List   Data Fields   Globals  

scs2mpfr.c

00001 /*
00002  * Author  : Defour David
00003  * Contact : David.Defour@ens-lyon.fr
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or 
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
00018  */
00019 
00020 
00021 
00022 #include "scs.h"
00023 #include "scs_private.h"
00024 
00025 /* Compile only if mpfr is present */
00026 
00027 #ifdef HAVE_MPFR_H
00028 
00029 
00030 /*
00031  * Convert a scs number into a MPFR number rounded to nearest
00032  */
00033 void scs_get_mpfr(scs_ptr x, mpfr_t rop){
00034     mpfr_t mp1;
00035     long int expo;
00036     int i;
00037 
00038     mpfr_set_ui(rop, 0, GMP_RNDN);
00039 
00040     /* mantissa */
00041     for (i=0; i<SCS_NB_WORDS; i++){
00042       mpfr_mul_2exp(rop, rop, SCS_NB_BITS, GMP_RNDN);
00043       mpfr_add_ui(rop, rop, X_HW[i], GMP_RNDN);
00044     }
00045 
00046     /* sign */
00047     if (X_SGN == -1) mpfr_neg(rop, rop, GMP_RNDN);
00048 
00049     /* exception */
00050     mpfr_init_set_d(mp1, X_EXP, GMP_RNDN); 
00051     mpfr_mul(rop, rop, mp1, GMP_RNDN);
00052 
00053     /* exponent */
00054     expo = (X_IND - SCS_NB_WORDS + 1) * SCS_NB_BITS;
00055 
00056     if (expo < 0)  mpfr_div_2exp(rop, rop, (unsigned int) -expo, GMP_RNDN);
00057     else           mpfr_mul_2exp(rop, rop, (unsigned int) expo, GMP_RNDN);
00058 
00059     mpfr_clear(mp1);
00060 }
00061 #endif /* HAVE_MPFR_H */

Generated on Tue Jun 17 10:15:51 2003 for SCSLib by doxygen1.2.15