Annotation of OpenXM_contrib/gmp/mpfr/set_si.c, Revision 1.1.1.1
1.1 maekawa 1: /* mpfr_set_si, mpfr_set_ui -- set a MPFR number from a machine integer
2:
3: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
4:
5: This file is part of the MPFR Library.
6:
7: The MPFR Library is free software; you can redistribute it and/or modify
8: it under the terms of the GNU Library General Public License as published by
9: the Free Software Foundation; either version 2 of the License, or (at your
10: option) any later version.
11:
12: The MPFR Library is distributed in the hope that it will be useful, but
13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15: License for more details.
16:
17: You should have received a copy of the GNU Library General Public License
18: along with the MPFR Library; see the file COPYING.LIB. If not, write to
19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20: MA 02111-1307, USA. */
21:
22: #include <stdio.h>
23: #include "gmp.h"
24: #include "gmp-impl.h"
25: #include "longlong.h"
26: #include "mpfr.h"
27:
28: void
29: #if __STDC__
30: mpfr_set_si(mpfr_ptr x, long i, unsigned char rnd_mode)
31: #else
32: mpfr_set_si(x, i, rnd_mode)
33: mpfr_ptr x;
34: long i;
35: unsigned char rnd_mode;
36: #endif
37: {
38: unsigned long xn, cnt; mp_limb_t ai;
39:
40: if (i==0) { SET_ZERO(x); return; }
41: xn = (PREC(x)-1)/BITS_PER_MP_LIMB;
42: ai = ABS(i);
43:
44: count_leading_zeros(cnt, ai);
45:
46: x -> _mp_d[xn] = ai << cnt;
47: /* don't forget to put zero in lower limbs */
48: MPN_ZERO(MANT(x), xn);
49: x -> _mp_exp = BITS_PER_MP_LIMB - cnt;
50: /* warning: don't change the precision of x! */
51: if (i*SIGN(x) < 0) CHANGE_SIGN(x);
52:
53: return;
54: }
55:
56: void
57: #if __STDC__
58: mpfr_set_ui(mpfr_ptr x, unsigned long i, unsigned char rnd_mode)
59: #else
60: mpfr_set_ui(x, i, rnd_mode)
61: mpfr_ptr x;
62: long i;
63: unsigned char rnd_mode;
64: #endif
65: {
66: unsigned int xn, cnt;
67:
68: if (i==0) { SET_ZERO(x); return; }
69: xn = (PREC(x)-1)/BITS_PER_MP_LIMB;
70: count_leading_zeros(cnt, (mp_limb_t) i);
71:
72: x -> _mp_d[xn] = ((mp_limb_t) i) << cnt;
73: /* don't forget to put zero in lower limbs */
74: MPN_ZERO(MANT(x), xn);
75: x -> _mp_exp = BITS_PER_MP_LIMB - cnt;
76: /* warning: don't change the precision of x! */
77: if (SIGN(x) < 0) CHANGE_SIGN(x);
78:
79: return;
80: }
81:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>