wrong results for SPACING and RRSPACING at compile time

Steve Kargl sgk@troutmask.apl.washington.edu
Wed Oct 4 20:41:00 GMT 2006


On Wed, Oct 04, 2006 at 10:04:35PM +0200, Dominique Dhumieres wrote:
> > I've re-open PR fortran/15441 about rrspacing.  Can you confirm
> > that spacing() is now doing the right thing?
> 
> I just finished rebuilding gfortran with your patch (among others).
> The situation is now much better, from the three problems I reported
> it remains only the following:
> 
> real x, xd, xu
> x = -3.0*epsilon(x)
> xd = abs(fraction(x))*set_exponent(real(radix(x), kind=kind(x)), 1+digits(x))
> print *, -3.0*epsilon(1.0)-x
> print *, x, spacing(x), spacing(-3.0*epsilon(1.0))
> print *, x, xd, rrspacing(x), rrspacing(-3.0*epsilon(1.0))
> end
> 
> gives
> 
>    0.000000    
>  -3.5762787E-07  2.8421709E-14  2.8421709E-14
>  -3.5762787E-07   0.000000      1.2582912E+07  1.2582912E+07
> 
> i.e., xd does not have the right value 1.2582912E+07.

So, this failure is not a spacing() or rrspacing() problem.
Looks like a set_exponent issue.

> Your test in pr15441
> 
> program h
>   real, parameter :: s = 0.375 * tiny(1.)
>   real x
>   x = s
>   print *, 's               =', s, ' <-- Subnormal named constant'
>   print *, 'x               =', x, ' <-- Subnormal variable'
>   print *, 'rrspacing(s)    =', rrspacing(s), ' <-- Constant folding'
>   print *, 'my_rrspacing(x) =', my_rrspacing(x), ' <-- Fortran code'
>   print *, 'rrspacing(x)    =', rrspacing(x),   ' <-- gfortran inline'
>   contains
>     function my_rrspacing(x)
>     implicit none
>     real my_rrspacing
>     real, intent(in) :: x
>     real y
>     y = abs(x)
>     if (y == 0.) then
>        my_rrspacing = 0.
>     else
>        my_rrspacing = scale(scale(y, - exponent(y)), digits(y))
>     end if
>     end function my_rrspacing
> end program h
> 
> gives
> 
>  s               =  4.4081038E-39  <-- Subnormal named constant
>  x               =  4.4081038E-39  <-- Subnormal variable
>  rrspacing(s)    =  8.5070592E+37  <-- Constant folding
>  my_rrspacing(x) =  7.3955710E-32  <-- Fortran code
>  rrspacing(x)    =            NaN  <-- gfortran inline
> 
> So there are still some problems! I'll try to investigate further.

What options and OS?  Also, the patch I sent had the 

if (x < tiny(x))
  {
  }

portion in simplify.c(gfc_simplify_rrspacing).  Did you delete
that section?

-- 
Steve



More information about the Fortran mailing list