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,972 of 5,127   
   Kay Diederichs to All   
   Re: FRACTION() seems broken in gfortran    
   19 Aug 25 12:15:37   
   
   From: kay.diederichs@gmx.net   
      
   Am 8/17/25 um 05:18 schrieb Steven G. Kargl:   
   > On Sat, 16 Aug 2025 20:40:13 -0500, Gary Scott wrote:   
   >   
   >> On 8/16/2025 7:02 PM, Steven G. Kargl wrote:   
   >>> On Fri, 15 Aug 2025 22:24:52 +0000, Lawrence D’Oliveiro wrote:   
   >>>   
   >>>> On Thu, 14 Aug 2025 11:21:00 +0800, Woozy Song wrote:   
   >>>>   
   >>>>> A program was going wrong, and found   
   >>>>> FRACTION(3.75)=0.9375 and FRACTION(2.5)=0.9375   
   >>>>   
   >>>> Broken as designed, according to the spec.   
   >>>>   
   >>>> Why on Earth does FRACTION have this meaning?   
   >>>   
   >>> To what spec are you referring?   
   >>>   
   >>> gfortran is giving the correct answer (although   
   >>> I suspect OP has a transcription problem with   
   >>> the second example).   
   >>>   
   >>   
   >> I think most casual, non-math, non-floating point experts would expect this:   
   >   
   > For someone programming in the Fortran language, I would expect   
   > that they would consult some form of documentation to learn why   
   > their expectation might be wrong.  For example, the gfortran   
   > documentation (which comes with the compiler) contains   
   >   
   >   
   > 8.119 ‘FRACTION’ -- Fractional part of the model representation   
   > ===============================================================   
   >   
   > _Synopsis_:   
   >       ‘Y = FRACTION(X)’   
   >   
   > _Description_:   
   >       ‘FRACTION(X)’ returns the fractional part of the model   
   >       representation of ‘X’.   
   >   
   > _Class_:   
   >       Elemental function   
   >   
   > _Arguments_:   
   >       X           The type of the argument shall be a ‘REAL’.   
   >   
   > _Return value_:   
   >       The return value is of the same type and kind as the argument.  The   
   >       fractional part of the model representation of ‘X’ is returned; it   
   >       is ‘X * RADIX(X)**(-EXPONENT(X))’.   
   >   
   > _Example_:   
   >            program test_fraction   
   >              real :: x   
   >              x = 178.1387e-4   
   >              print *, fraction(x), x * radix(x)**(-exponent(x))   
   >            end program test_fraction   
   >   
      
   Thank you, Steve.   
      
   The following program, adapted from the Example in the documentation you cite:   
      
   program test_fraction   
      real :: x   
      x = 3.75   
      print *, fraction(x), x   
      print *, x * radix(x)**(-exponent(x))   
   end program test_fraction   
      
   prints:   
      0.937500000       3.75000000   
       0.00000000   
      
   but I was expecting it to print:   
      0.937500000       3.75000000   
      0.937500000   
      
   because the documentation says that fraction(x) is the same as  x *   
   radix(x)**(-exponent(x)) .   
      
   I suggest that the documentation is wrong, and should say   
   ' ... model representation of ‘X’ is returned; it is ‘X *    
   EAL(RADIX(X))**(-EXPONENT(X))’.   
      
   Concerning the OP's finding that FRACTION(2.5) is printed as 0.9375:   
   I cannot reproduce that with gfortran 11.5.0 or 13.3.1 or 14.2.1 which all   
   correctly calculate 0.625 .   
      
   So to me this is a documentation bug, and possibly a bug in gfortran 12.2 .   
      
   Hope this helps,   
   Kay   
      
   --- 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