Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.fortran Subject: Re: conversion to double precision Message-ID: Date: 6 Aug 90 07:22:41 GMT References: <25734@cs.yale.edu> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 42 In-Reply-To: johnk%suned@cs.yale.edu's message of 4 Aug 90 22:23:38 GMT 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