Annotation of OpenXM_contrib/gmp/mpfr/get_z_exp.c, Revision 1.1
1.1 ! ohara 1: /* mpfr_get_z_exp -- get a multiple-precision integer and an exponent
! 2: from a floating-point number
! 3:
! 4: Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
! 5:
! 6: This file is part of the MPFR Library.
! 7:
! 8: The MPFR Library is free software; you can redistribute it and/or modify
! 9: it under the terms of the GNU Lesser General Public License as published by
! 10: the Free Software Foundation; either version 2.1 of the License, or (at your
! 11: option) any later version.
! 12:
! 13: The MPFR Library is distributed in the hope that it will be useful, but
! 14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
! 16: License for more details.
! 17:
! 18: You should have received a copy of the GNU Lesser General Public License
! 19: along with the MPFR Library; see the file COPYING.LIB. If not, write to
! 20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 21: MA 02111-1307, USA. */
! 22:
! 23: #include "gmp.h"
! 24: #include "gmp-impl.h"
! 25: #include "longlong.h"
! 26: #include "mpfr.h"
! 27: #include "mpfr-impl.h"
! 28:
! 29: /* puts the mantissa of f into z, and returns 'exp' such that f = z * 2^exp
! 30: *
! 31: * 0 doesn't have an exponent, therefore the returned exponent in this case
! 32: * isn't really important. We choose to return __mpfr_emin because
! 33: * 1) it is in the exponent range [__mpfr_emin,__mpfr_emax],
! 34: * 2) the smaller a number is (in absolute value), the smaller its
! 35: * exponent is. In other words, the f -> exp function is monotonous
! 36: * on nonnegative numbers.
! 37: * Note that this is different from the C function frexp().
! 38: */
! 39:
! 40: mp_exp_t
! 41: mpfr_get_z_exp (mpz_ptr z, mpfr_srcptr f)
! 42: {
! 43: mp_size_t fn;
! 44: int sh;
! 45:
! 46: MPFR_ASSERTN(MPFR_IS_FP(f));
! 47:
! 48: if (MPFR_IS_ZERO(f))
! 49: {
! 50: mpz_set_ui (z, 0);
! 51: return __mpfr_emin;
! 52: }
! 53:
! 54: fn = 1 + (MPFR_PREC(f) - 1) / BITS_PER_MP_LIMB;
! 55:
! 56: /* check whether allocated space for z is enough */
! 57: if (ALLOC(z) < fn)
! 58: MPZ_REALLOC(z, fn);
! 59:
! 60: sh = (mp_prec_t) fn * BITS_PER_MP_LIMB - MPFR_PREC(f);
! 61: if (sh)
! 62: mpn_rshift (PTR(z), MPFR_MANT(f), fn, sh);
! 63: else
! 64: MPN_COPY (PTR(z), MPFR_MANT(f), fn);
! 65:
! 66: SIZ(z) = fn;
! 67:
! 68: MPFR_ASSERTN((mp_exp_unsigned_t) MPFR_EXP(f) - MPFR_EMIN_MIN
! 69: >= (mp_exp_unsigned_t) MPFR_PREC(f));
! 70: return MPFR_EXP(f) - MPFR_PREC(f);
! 71: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>