johnk%suned@cs.yale.edu (john james kuszewski) (08/05/90)
I'm having some difficulty converting REAL variables to DOUBLE PRECISION. All the manuals I've seen say that the REAL value is put in the most significant portion of the D.P. variable and the least significant portion is zeroed out. However, when I execute REAL X X = 1.23E0 TYPE *, 'SINGLE', X TYPE *, 'DOUBLE', DBLE(X) I get SINGLE 1.230000 DOUBLE 1.23000001907349 If I'm reading the manual properly, those least-significant D.P. digits should be zeros. What's the problem here? If this is what FORTRAN is supposed to do, how can I force it to zero out those least-significant digits? Sorry if this is a stupid question, but it's driving me nuts. Thanks. John Kuszewski kuszewsk@euler.biology.yale.edu .sig under construction
burley@world.std.com (James C Burley) (08/06/90)
In article <25734@cs.yale.edu> johnk%suned@cs.yale.edu (john james kuszewski) writes:
I'm having some difficulty converting REAL variables to DOUBLE
PRECISION. All the manuals I've seen say that the REAL value
is put in the most significant portion of the D.P. variable and
the least significant portion is zeroed out. However, when I
execute
REAL X
X = 1.23E0
TYPE *, 'SINGLE', X
TYPE *, 'DOUBLE', DBLE(X)
I get
SINGLE 1.230000
DOUBLE 1.23000001907349
If I'm reading the manual properly, those least-significant D.P.
digits should be zeros. What's the problem here? If this is what
FORTRAN is supposed to do, how can I force it to zero out those
least-significant digits? Sorry if this is a stupid question,
but it's driving me nuts.
Thanks.
John Kuszewski
kuszewsk@euler.biology.yale.edu
I think the answer here is that the least-significant digits ARE being
zeroed out -- in BINARY, not in decimal. Zeroing trailing binary digits
does not necessarily imply zeroing corresponding trailing decimal digits.
Another view: "1.230000", the SINGLE number, also has "phantom" binary
zeroes following it, but because the system knows not to print more than
7 significant digits, you don't see the "...01907349" at the end.
Try this experiment: write a program to input a DOUBLE from the tty, convert
it to a SINGLE, and display both. Enter 1.2300000000000. You'll probably
find that while the DOUBLE looks a lot like your original input (perhaps with
a slight error at the very end), the SINGLE will be something like "1.229799".
James Craig Burley, Software Craftsperson burley@world.std.com
FC138001@ysub.ysu.edu (Phil Munro) (08/06/90)
Perhaps DBLE needs to be declared as DOUBLE PRECEISION or REAL*8 itself, with your compiler?