This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: Formatted Read Accuracy


This is a tough one to diagnose.

You input 67.9936 from somewhere, in that character sequence.  How do
you know it "becomes" 67.9935989?  Are you printing it out?  Are you
looking in storage?  Are you specifying that "xllt" is a particular
format, other than FLOAT?  

The only sure way to know what's going on is to confirm that "line"
indeed contains 67.9936 when you input it, and then look at storage
through a debugger to confirm that it is 67.9935989 afterwards.  You may
have to fiddle with your code to make sure you get the precision you're
looking for.

If you're getting different behavior in different compilers, it's
probably because the compilers were changed to better conform to
standards.

On the whole, the conversion of floating point numbers from their
character representation to internal format is problematic.  A Fortran
77 guide or textbook can clarify it.  Don't get too uptight about what
the >compiler< is doing, check out what the >language< is >supposed to
do< first, and then make sure your compiler is doing it.

Joe

> -----Original Message-----
> From: gcc-help-owner@gcc.gnu.org 
> [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Emil Block
> Sent: Wednesday, October 09, 2002 07:38
> To: gcc-help@gcc.gnu.org
> Subject: Formatted Read Accuracy
> 
> 
> When reading a number from an input file with a formatted 
> read statement the value is not represented correctly when 
> using the G77 compiler. For example,
> 
>    read (line,3) xllt
> 3  format(f9.4)  
>      
> input xllt is  67.9936  and it becomes 67.9935989  
> 
> Anyone know how to correct this?
> 
> Blime
> 


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