Annotation of OpenXM_contrib/gmp/mpfr/set_f.c, Revision 1.1.1.2
1.1 maekawa 1: /* mpfr_set_f -- set a MPFR number from a GNU MPF number
2:
1.1.1.2 ! ohara 3: Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
1.1 maekawa 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
1.1.1.2 ! ohara 8: it under the terms of the GNU Lesser General Public License as published by
! 9: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1 maekawa 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
1.1.1.2 ! ohara 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! ohara 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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"
1.1.1.2 ! ohara 27: #include "mpfr-impl.h"
1.1 maekawa 28:
1.1.1.2 ! ohara 29: int
! 30: mpfr_set_f (mpfr_ptr y, mpf_srcptr x, mp_rnd_t rnd_mode)
1.1 maekawa 31: {
1.1.1.2 ! ohara 32: mp_limb_t *my, *mx, *tmp;
! 33: unsigned long cnt, sx, sy;
! 34: int inexact;
1.1 maekawa 35: TMP_DECL(marker);
36:
1.1.1.2 ! ohara 37: if (SIZ(x) * MPFR_SIGN(y) < 0)
! 38: MPFR_CHANGE_SIGN (y);
1.1 maekawa 39:
1.1.1.2 ! ohara 40: MPFR_CLEAR_FLAGS (y);
1.1 maekawa 41:
1.1.1.2 ! ohara 42: sx = ABS(SIZ(x)); /* number of limbs of the mantissa of x */
! 43: sy = 1 + (MPFR_PREC(y) - 1) / BITS_PER_MP_LIMB;
! 44: my = MPFR_MANT(y);
! 45: mx = PTR(x);
1.1 maekawa 46:
1.1.1.2 ! ohara 47: if (sx == 0) /* x is zero */
! 48: {
! 49: MPFR_SET_ZERO(y);
! 50: return 0; /* 0 is exact */
! 51: }
! 52:
! 53: count_leading_zeros(cnt, mx[sx - 1]);
1.1 maekawa 54:
1.1.1.2 ! ohara 55: if (sy <= sx) /* we may have to round even when sy = sx */
1.1 maekawa 56: {
57: unsigned long xprec = sx * BITS_PER_MP_LIMB;
58:
1.1.1.2 ! ohara 59: TMP_MARK(marker);
1.1 maekawa 60: tmp = (mp_limb_t*) TMP_ALLOC(xprec);
1.1.1.2 ! ohara 61: if (cnt)
! 62: mpn_lshift(tmp, mx, sx, cnt);
! 63: else
! 64: MPN_COPY(tmp, mx, sx);
! 65: mpfr_round_raw (my, tmp, xprec, (SIZ(x)<0), MPFR_PREC(y), rnd_mode,
! 66: &inexact);
! 67: TMP_FREE(marker);
1.1 maekawa 68: }
69: else
70: {
1.1.1.2 ! ohara 71: if (cnt)
! 72: mpn_lshift(my + sy - sx, mx, sx, cnt);
! 73: else
! 74: MPN_COPY(my + sy - sx, mx, sy);
1.1 maekawa 75: MPN_ZERO(my, sy - sx);
76: /* no rounding necessary, since y has a larger mantissa */
1.1.1.2 ! ohara 77: inexact = 0;
1.1 maekawa 78: }
79:
1.1.1.2 ! ohara 80: MPFR_EXP(y) = EXP(x) * BITS_PER_MP_LIMB - cnt;
1.1 maekawa 81:
1.1.1.2 ! ohara 82: return inexact;
1.1 maekawa 83: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>