home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.fortran      Putting John Backus on a giant pedestal      5,127 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 4,989 of 5,127   
   Steven G. Kargl to All   
   Re: FRACTION() seems broken in gfortran    
   10 Sep 25 22:28:22   
   
   From: sgk@REMOVEtroutmask.apl.washington.edu   
      
   On Wed, 10 Sep 2025 07:06:53 +0000, Lawrence D’Oliveiro wrote:   
      
   > On Wed, 10 Sep 2025 02:15:55 -0000 (UTC), Steven G. Kargl wrote:   
   >   
   >> Intent to column 7 and the following worked over 66 years ago.   
   >>   
   >> program real_kinds   
   >>    real x fraction(x) = mod(x,1.)   
   >>    x = 3.12345 print *, fraction(x)   
   >> end program real_kinds   
   >   
   > Ignoring the fact that’s not valid FORTRAN 66 or FORTRAN IV (what other   
   > spec was valid 66 years ago?), it’s not relevant to the FRACTION()   
   > function we are discussing, is it?   
      
   Yeah, A little loose with syntax.  You however are overlooking   
   the key point: F66 had a statement function.   
      
         FRAC(X) = AMOD(X, 1.)   
         X = 3.12345   
         Y = FRAC(X)   
         WRITE(7) Y   
         END   
      
   This is your python example of a user written fraction()   
   function, and is Fortran 66 conforming.  So, returning to modern   
   Fortran, if you want fraction() to return the decimal fractional   
   part of a number, use a statement function or better yet a   
   contained subprogram.   
      
      
   program foo   
      implicit none   
      real x   
      x = 3.12345   
      print *, fraction(x)   
      contains   
         elemental function fraction(x) result(r)   
            real r   
            real, intent(in) :: x   
            r = mod(x,1.)   
         end function fraction   
   end program foo   
      
   --   
   steve   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca