This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH/gfortran] Chop bits of subnormal numbers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]