[PATCH/gfortran] Chop bits of subnormal numbers

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Sat May 7 22:31:00 GMT 2005


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



More information about the Gcc-patches mailing list