Annotation of OpenXM_contrib/gmp/mpfr/set.c, Revision 1.1.1.2
1.1 maekawa 1: /* mpfr_set -- copy of a floating-point number
2:
1.1.1.2 ! ohara 3: Copyright 1999, 2001 Free Software Foundation.
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 "gmp.h"
23: #include "gmp-impl.h"
24: #include "mpfr.h"
1.1.1.2 ! ohara 25: #include "mpfr-impl.h"
1.1 maekawa 26:
1.1.1.2 ! ohara 27: /* set a to abs(b) * signb: a=b when signb = SIGN(b), a=abs(b) when signb=1 */
! 28: int
! 29: mpfr_set4 (mpfr_ptr a, mpfr_srcptr b, mp_rnd_t rnd_mode, int signb)
1.1 maekawa 30: {
1.1.1.2 ! ohara 31: int inex;
1.1 maekawa 32:
1.1.1.2 ! ohara 33: if (MPFR_IS_NAN(b))
! 34: {
! 35: MPFR_CLEAR_FLAGS(a);
! 36: MPFR_SET_NAN(a);
! 37: MPFR_RET_NAN;
1.1 maekawa 38: }
1.1.1.2 ! ohara 39:
! 40: if (MPFR_IS_INF(b))
! 41: {
! 42: MPFR_CLEAR_FLAGS(a);
! 43: MPFR_SET_INF(a);
! 44: inex = 0;
! 45: }
! 46: else
! 47: {
! 48: mp_limb_t *ap;
! 49: mp_prec_t aq;
! 50: int carry;
! 51:
! 52: MPFR_CLEAR_FLAGS(a);
! 53:
! 54: ap = MPFR_MANT(a);
! 55: aq = MPFR_PREC(a);
! 56:
! 57: carry = mpfr_round_raw(ap, MPFR_MANT(b), MPFR_PREC(b), (signb < 0),
! 58: aq, rnd_mode, &inex);
! 59: MPFR_EXP(a) = MPFR_EXP(b);
! 60:
! 61: if (carry)
! 62: {
! 63: mp_exp_t exp = MPFR_EXP(a);
! 64:
! 65: if (exp == __mpfr_emax)
! 66: return mpfr_set_overflow(a, rnd_mode, signb);
! 67:
! 68: MPFR_EXP(a)++;
! 69: ap[(MPFR_PREC(a)-1)/BITS_PER_MP_LIMB] = GMP_LIMB_HIGHBIT;
! 70: }
! 71: }
! 72:
! 73: if (MPFR_SIGN(a) * signb < 0)
! 74: MPFR_CHANGE_SIGN(a);
! 75: MPFR_RET(inex);
1.1 maekawa 76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>