[fortran,patch] Call mpfr_check_range after setting emin/emax

FX fxcoudert@gmail.com
Sun May 18 18:02:00 GMT 2008


The two patchlets below regtest fine on my system (x86_64-linux, both  
-m32 and -m64) and fix the issue I am seeing with gfortran.dg/ 
nearest_4.f90. Is it OK to commit?

FX


PS: this leads me to propose that maintainers use for the development  
machines GMP and MPFR libraries with assertions turned on, as this  
can help spotting some issues with the way we use these libraries  
(and I have not seen any remarkable slow-down since I use them).


> For a few months now, I've seen a failure of gfortran.dg/ 
> nearest_4.f90 on my x86_64-linux build machine; the fact that noone  
> else saw it, I suppose, is because I use GMP and MPFR built with  
> internal checking (assertions) enabled. The following patch fixes it:
>
> Index: simplify.c
> ===================================================================
> --- simplify.c  (revision 134839)
> +++ simplify.c  (working copy)
> @@ -2821,6 +2821,7 @@ gfc_simplify_nearest (gfc_expr *x, gfc_e
>    mpfr_set_emin ((mp_exp_t) gfc_real_kinds[kind].min_exponent -
>                 mpfr_get_prec(result->value.real) + 1);
>    mpfr_set_emax ((mp_exp_t) gfc_real_kinds[kind].max_exponent - 1);
> +  mpfr_check_range (result->value.real, 0, GMP_RNDU);
>
>    if (mpfr_sgn (s->value.real) > 0)
>      {
>
>
> It follows the MPFR doc, which says that it's our responsability to  
> make sure a real number is still in range after we've used  
> mpfr_set_e{min,max}. These functions are used in another place in  
> arith.c, which I propose to also fix:
>
> Index: arith.c
> ===================================================================
> --- arith.c     (revision 134839)
> +++ arith.c     (working copy)
> @@ -384,6 +384,7 @@ gfc_check_real_range (mpfr_t p, int kind
>        en = gfc_real_kinds[i].min_exponent - gfc_real_kinds 
> [i].digits + 1;
>        mpfr_set_emin ((mp_exp_t) en);
>        mpfr_set_emax ((mp_exp_t) gfc_real_kinds[i].max_exponent);
> +      mpfr_check_range (q, 0, GFC_RND_MODE);
>        mpfr_subnormalize (q, 0, GFC_RND_MODE);
>
>        /* Reset emin and emax.  */

-- 
François-Xavier Coudert
http://www.homepages.ucl.ac.uk/~uccafco/



More information about the Gcc-patches mailing list