1 /*
2 * Copyright (C) 2002 David Defour, Catherine Daramy, and Florent de Dinechin
3 *
4 * Author: David Defour
5 *
6 * This file is part of scslib, the Software Carry-Save multiple-precision
7 * library, which has been developed by the Arénaire project at École normale
8 * supérieure de Lyon.
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25
26 #include "scs.h"
27 #include "scs_private.h"
28
29 /* Compile only if gmp is present */
30
31 #ifdef HAVE_GMP_H
32
33 /*
34 * Convert a scs number into a MPF number (GMP)
35 */
scs_get_mpf(scs_ptr x,mpf_t rop)36 void scs_get_mpf(scs_ptr x, mpf_t rop){
37 mpf_t mp1;
38 long int expo;
39 int i;
40
41 mpf_set_ui(rop, 0);
42
43 /* mantissa */
44 for (i=0; i<SCS_NB_WORDS; i++){
45 mpf_mul_2exp(rop, rop, SCS_NB_BITS);
46 mpf_add_ui(rop, rop, X_HW[i]);
47 }
48
49 /* sign */
50 if (X_SGN == -1) mpf_neg(rop, rop);
51
52 /* exception */
53 mpf_init_set_d(mp1, X_EXP); mpf_mul(rop, rop, mp1);
54
55 /* exponent */
56 expo = (X_IND - SCS_NB_WORDS + 1) * SCS_NB_BITS;
57
58 if (expo < 0) mpf_div_2exp(rop, rop, (unsigned int) -expo);
59 else mpf_mul_2exp(rop, rop, (unsigned int) expo);
60
61 mpf_clear(mp1);
62 }
63 #endif /*HAVE_GMP_H*/
64