diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-28 11:32:57 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-01-28 11:32:57 +0000 |
commit | 2f7d3ed598d3f6ec2925673ebc527d729a253576 (patch) | |
tree | 1c842ec5e01cbe3847146f6ea18d58a0da874f0f | |
parent | d9c942c32b39399e742c63db32f7e8d6abeed91f (diff) | |
download | mpfr-2f7d3ed598d3f6ec2925673ebc527d729a253576.tar.gz |
Added comments and a temporary fix.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2649 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | frac.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -1,6 +1,6 @@ /* mpfr_frac -- Fractional part of a floating-point number. -Copyright 2002, 2003 Free Software Foundation, Inc. +Copyright 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of the MPFR Library. @@ -25,6 +25,9 @@ MA 02111-1307, USA. */ #include "mpfr.h" #include "mpfr-impl.h" +/* Optimization note: it is not a good idea to call mpfr_integer_p, + as some cases will take longer (the number may be parsed twice). */ + int mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode) { @@ -62,32 +65,39 @@ mpfr_frac (mpfr_ptr r, mpfr_srcptr u, mp_rnd_t rnd_mode) up = MPFR_MANT(u); sh = ue % BITS_PER_MP_LIMB; k = up[un] << sh; + /* the first bit of the fractional part is the MSB of k */ if (k != 0) { int cnt; count_leading_zeros(cnt, k); + /* first bit 1 of the fractional part -> MSB of the number */ re = -cnt; sh += cnt; + MPFR_ASSERTN (sh < BITS_PER_MP_LIMB); k <<= cnt; } else { re = sh - BITS_PER_MP_LIMB; - while ((k = up[--un]) == 0) + /* searching for the first bit 1 (exists since u isn't an integer) */ + while (up[--un] == 0) re -= BITS_PER_MP_LIMB; MPFR_ASSERTN(un >= 0); + k = up[un]; count_leading_zeros(sh, k); re -= sh; k <<= sh; } /* The exponent of r will be re */ + /* un: index of the limb of u that contains the first bit 1 of the FP */ ue -= re; /* number of bits of u to discard */ fq = uq - ue; /* number of bits of the fractional part of u */ - t = fq > MPFR_PREC(r) ? + /* Temporary fix */ + t = /* fq > MPFR_PREC(r) */ (MPFR_PREC(r) - 1) / BITS_PER_MP_LIMB < un ? (mpfr_init2 (tmp, (un + 1) * BITS_PER_MP_LIMB), tmp) : r; /* t has enough precision to contain the fractional part of u */ /* If we use a temporary variable, we take the non-significant bits |