Main Page   Data Structures   File List   Data Fields   Globals  

scs2mpf.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 #include "scs.h"
00022 #include "scs_private.h"
00023 
00024 /* Compile only if gmp is present */
00025 
00026 #ifdef HAVE_GMP_H
00027 
00028 /*
00029  * Convert a scs number into a MPF number (GMP)
00030  */
00031 void scs_get_mpf(scs_ptr x, mpf_t rop){
00032     mpf_t mp1;
00033     long int expo;
00034     int i;
00035 
00036     mpf_set_ui(rop, 0);
00037 
00038     /* mantissa */
00039     for (i=0; i<SCS_NB_WORDS; i++){
00040       mpf_mul_2exp(rop, rop, SCS_NB_BITS);
00041       mpf_add_ui(rop, rop, X_HW[i]);
00042     }
00043 
00044     /* sign */
00045     if (X_SGN == -1) mpf_neg(rop, rop);
00046 
00047     /* exception */
00048     mpf_init_set_d(mp1, X_EXP); mpf_mul(rop, rop, mp1);
00049 
00050     /* exponent */
00051     expo = (X_IND - SCS_NB_WORDS + 1) * SCS_NB_BITS;
00052 
00053     if (expo < 0)  mpf_div_2exp(rop, rop, (unsigned int) -expo);
00054     else           mpf_mul_2exp(rop, rop, (unsigned int) expo);
00055 
00056     mpf_clear(mp1);
00057 }
00058 #endif /*HAVE_GMP_H*/

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