This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH/gfortran] Chop bits of subnormal numbers
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 08 May 2005 00:31:44 +0200
- Subject: Re: [PATCH/gfortran] Chop bits of subnormal numbers
- References: <20050507212510.GA25826@troutmask.apl.washington.edu>
Steve Kargl wrote:
> + int j, k;
> + char *bin, *s;
> + mp_exp_t e;
> +
> + bin = mpfr_get_str(NULL, &e, gfc_real_kinds[i].radix, 0, p, GMP_RNDN);
> + k = gfc_real_kinds[i].digits - (gfc_real_kinds[i].min_exponent - e);
> + for (j = k; j < gfc_real_kinds[i].digits; j++)
> + bin[j] = '0';
> + /* Need space for '0.', bin, 'E', and e */
> + s = (char *) gfc_getmem(strlen(bin)+10);
> + sprintf(s, "0.%sE%d", bin, (int) e);
> + mpfr_set_str (p, s, gfc_real_kinds[i].radix, GMP_RNDN);
This won't work for negative values of p. Apart from this, this looks fine.
- Tobi