X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-Id: <4D74FD73.7010900@saic.com> Date: Mon, 07 Mar 2011 10:44:51 -0500 From: "Roger K. Wells" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: 1.7.8: Fortran I/O rounding inaccuracy References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 03/07/2011 04:39 AM, Thomas Henlich wrote: > Hi, > > I found the following bug in cygwin 1.7.8 on Windows XP: > > Fortran I/O rounding truncates the result after a certain number of > digits. The following program: > === > write(*, '(f35.32)') 0.14285714285714285d0 > end > === > gives this output: > 0.14285714285714284921269000000000 > The expected output is: > 0.14285714285714284921269268124888 > > This is in violation of the Fortran 2008 standard which demands: > > === > 10.7.2.3.7 I/O rounding mode > > 2. In what follows, the term "decimal value" means the exact decimal number as > given by the character string, while the term "internal value" means the number > actually stored in the processor. For example, in dealing with the decimal > constant 0.1, the decimal value is the mathematical quantity 1/10, which has no > exact representation in binary form. Formatted output of real data involves > conversion from an internal value to a decimal value; formatted input involves > conversion from a decimal value to an internal value. > > 3. When the I/O rounding mode is UP, the value resulting from conversion shall > be the smallest representable value that is greater than or equal to the > original value. When the I/O rounding mode is DOWN, the value resulting > from conversion shall be the largest representable value that is less than or > equal to the original value. ... > === > > Applied to the example this means, 0.14285714285714284921269268124888 > is the largest representable > (with 32 decimal digits) value that is less than the original value (binary > 1.001001001001001001001001001001001001001001001001001 * 2^-3 = decimal > 0.1428571428571428492126926812488818...), but > 0.14285714285714284921269000000000 is NOT. > > The problem seems limited to the Fortran language, because the C call > printf("%35.32f\n", 0.14285714285714285) prints the expected result: > 0.14285714285714284921269268124888 > > -- > Problem reports: http://cygwin.com/problems.html > FAQ: http://cygwin.com/faq/ > Documentation: http://cygwin.com/docs.html > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > > uname -a: CYGWIN_NT-6.1 rwells-w7 1.7.8(0.236/5/3) 2011-03-01 09:36 i686 Cygwin round.f: program round write(*,'(f35.32)') 0.14285714285714285d0 end output: 0.14285714285714284921269268124888 did I miss something? HTH, roger wells -- Roger Wells, P.E. SAIC 221 Third St Newport, RI 02840 401-847-4210 (voice) 401-849-1585 (fax) roger DOT k DOT wells AT saic DOT com -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple