[Bug fortran/38188] Inconsistent function results depending on irrelevant write statement

2008-11-20 Thread dojo at masterleep dot com


--- Comment #3 from dojo at masterleep dot com  2008-11-20 17:55 ---
Oops, sorry for missing that.  Thank you for the help.  I was led astray
because for mysterious reasons it always worked before...


-- 

dojo at masterleep dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38188



[Bug fortran/38188] Inconsistent function results depending on irrelevant write statement

2008-11-19 Thread pinskia at gmail dot com


--- Comment #1 from pinskia at gmail dot com  2008-11-20 07:05 ---
Subject: Re:   New: Inconsistent function results depending on irrelevant write
statement

I don't think INF is the same as infinity. It is most like implict  
declared variable with an undefined value.

Sent from my iPhone

On Nov 19, 2008, at 10:52 PM, dojo at masterleep dot com
[EMAIL PROTECTED] 
  wrote:

 I am getting unreliable results from a small function using the latest
 prepackaged Mac OS build (PPC) available from the wiki download  
 page.  The
 function behaves correctly if an otherwise irrelevant write  
 statement is added.
 When the statement is removed, the function returns gibberish.  This  
 is
 ancient code which worked on older versions of gfortran, so  
 hopefully I haven't
 overlooked an obvious problem...

 $ uname -a
 Darwin Numenor 9.5.0 Darwin Kernel Version 9.5.0: Wed Sep  3  
 11:29:43 PDT 2008;
 root:xnu-1228.7.58~1/RELEASE_I386 i386

 $ gfortran --version
 GNU Fortran (GCC) 4.4.0 20080823 (experimental) [trunk revision  
 139508]

 $ cat xx.f
program xx
real xa(102)
do 10 i=1,100
 10  xa(i)=float(i)
call scale (xa,23.,100,1)
write (*,*) xa(101), xa(102)
end


subroutine scale(arr,axlen,npts,kcycle)
real :: arr(*),axlen,minval,maxval,val
integer :: npts,kcycle
minval = +INF
maxval = -INF
do i=0,npts-1
val=arr(1+kcycle*i)
minval=amin1(val,minval)
maxval=amax1(val,maxval)
end do
arr(npts*kcycle+1)=minval
arr(npts*kcycle+kcycle+1)=(maxval-minval)/axlen
 c   If the following line is uncommented, the function will work
 c   write (*,*) 3
end subroutine scale


 # Correct function result (write statement is left in)
 $ gfortran -o xx xx.f
 $ xx
   3
   0.000   4.3478260

 # Incorrect function result (write statement is commented out)
 $ gfortran -o xx xx.f
 $ xx
 -2.13906214E+09  1.86005408E+08


 -- 
   Summary: Inconsistent function results depending on  
 irrelevant
write statement
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dojo at masterleep dot com


 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38188



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38188



[Bug fortran/38188] Inconsistent function results depending on irrelevant write statement

2008-11-19 Thread burnus at gcc dot gnu dot org


--- Comment #2 from burnus at gcc dot gnu dot org  2008-11-20 07:20 ---
 I don't think INF is the same as infinity. It is most like implict  
 declared variable with an undefined value.

Exactly. With IMPLICIT NONE one sees that INF is an (implicitly typed) integer
variable, which has an undefined value.

minval = +INF
maxval = -INF

How about:

minval = huge(minval) ! largest finite value
maxval = -huge(minval)! smallest finite value

or shorter (untested)

  min = minval(arr( [(1+kcycle*i, i=0,npts-1)] )
  max = maxval(arr( [(1+kcycle*i, i=0,npts-1)] )

where (g)Fortran does internally what you want.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38188