diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-01-11 17:25:28 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2001-01-11 17:25:28 +0000 |
commit | 79ecd939b31f956bb3b2a20ad233bc2c6ffa4368 (patch) | |
tree | ec3fd9213abadd0d68be78542a705453386d6664 | |
parent | 6b8ae039e4441c419179c4696dc82b592c2f6710 (diff) | |
download | mpfr-79ecd939b31f956bb3b2a20ad233bc2c6ffa4368.tar.gz |
fixed bug for +0000E0
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@979 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | set_str_raw.c | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/set_str_raw.c b/set_str_raw.c index 56b166042..4561daa46 100644 --- a/set_str_raw.c +++ b/set_str_raw.c @@ -1,6 +1,6 @@ /* mpfr_set_str_raw -- set a floating-point number from a binary string -Copyright (C) 1999 Free Software Foundation. +Copyright (C) 1999-2001 Free Software Foundation. This file is part of the MPFR Library. @@ -98,33 +98,40 @@ mpfr_set_str_raw (x, str) else expn=k; endstr2 = str2; - *str2 = (char) 0; /* end of string */ - l = (strlen(str0) - 1) / BITS_PER_MP_LIMB + 1; str2 = str0; - if (l > xsize) { - fprintf (stderr, "Error: mantissa larger than precision of destination variable in mpfr_set_str_raw\n"); - exit (1); + l = endstr2 - str0; /* length of mantissa */ + if (l == 0) { /* input is zero */ + MPFR_SET_ZERO(x); } + else { + l = (l-1) / BITS_PER_MP_LIMB + 1; + str2 = str0; - /* str2[0]..endstr2[-1] contains the mantissa */ - for (k = 1; k <= l; k++) - { - j = 0; - xp[xsize - k] = 0; - while (str2<endstr2 && j < BITS_PER_MP_LIMB) - { - xp[xsize - k] = (xp[xsize - k] << 1) + (*str2 - '0'); - str2++; j++; - } - xp[xsize - k] <<= (BITS_PER_MP_LIMB - j); + if (l > xsize) { + fprintf (stderr, "Error: mantissa larger than precision of destination variable in mpfr_set_str_raw\n"); + exit (1); } - for (; k <= xsize; k++) { xp[xsize - k] = 0; } - - count_leading_zeros(cnt, xp[xsize - 1]); - if (cnt) mpn_lshift(xp, xp, xsize, cnt); - - MPFR_EXP(x) = expn - cnt; - MPFR_SIZE(x) = xsize; if (negative) MPFR_CHANGE_SIGN(x); + /* str2[0]..endstr2[-1] contains the mantissa */ + for (k = 1; k <= l; k++) + { + j = 0; + xp[xsize - k] = 0; + while (str2<endstr2 && j < BITS_PER_MP_LIMB) + { + xp[xsize - k] = (xp[xsize - k] << 1) + (*str2 - '0'); + str2++; j++; + } + xp[xsize - k] <<= (BITS_PER_MP_LIMB - j); + } + + for (; k <= xsize; k++) { xp[xsize - k] = 0; } + + count_leading_zeros(cnt, xp[xsize - 1]); + if (cnt) mpn_lshift(xp, xp, xsize, cnt); + + MPFR_EXP(x) = expn - cnt; + MPFR_SIZE(x) = xsize; if (negative) MPFR_CHANGE_SIGN(x); + } (*__gmp_free_func) (str0, alloc); |