This is the mail archive of the mailing list for the GNU Fortran 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: wrong results for SPACING and RRSPACING at compile time

> 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))


 -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.

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'
    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.
       my_rrspacing = scale(scale(y, - exponent(y)), digits(y))
    end if
    end function my_rrspacing
end program h


 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.

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