X-Spam-Check-By: sourceware.org Message-ID: <440C00FB.5020103@cs.unipr.it> Date: Mon, 06 Mar 2006 10:29:31 +0100 From: Roberto Bagnara User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050929 Thunderbird/1.0.7 Fedora/1.0.7-1.1.fc4 Mnenhy/0.7.3.0 MIME-Version: 1.0 To: Jim Easton CC: cygwin AT cygwin DOT com, "The Parma Polyhedra Library developers' list" Subject: Re: Precision of doubles and stdio References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 Jim Easton wrote: > Dear Mr. Bagnara, > > Roberto Bagnara wrote: > ... >> does this on Linux/i686 >> >> $ a.out >> 70.9 >> 70.900000000000005684341886080801486968994140625 >> >> and does the following under Cygwin on the same machine: > ... >> $ ./a.exe >> 70.9 >> 70.90000000000000568434188608080148696899414 >> >> Why? Is there a way to reconcile the two behaviors? >> Notice that I know about the x87 and its vaguaries: >> nonetheless I wonder why such a scanf immediately >> followed by a printf shows a difference between >> Cygwin and Linux. > > With all due respect, why would you want to? With double you are > guaranteed only 16 or so digits - the rest is noise. Frankly I am > amazed that it agrees as far as it does. Dear Jim, what is and what is not noise depends on the application. In our applications we systematically use controlled rounding on IEEE 754 floating point numbers. In the end, what we obtain (in memory) are definite (i.e., provably correct) lower or upper bounds of some quantities. Call `x' such a quantity, and suppose we have that our computed upper bound for `x' is the IEEE 754 Double Precision number 0x4051b9999999999a, that is (exactly!), 70.900000000000005684341886080801486968994140625. If that number is (wrongly!) printed as 70.90000000000000568434188608080148696899414 then we lose correctness, since x <= 70.900000000000005684341886080801486968994140625 does not imply x <= 70.90000000000000568434188608080148696899414. So, the final "0625" is not "noise" in our applications: it is what may make the difference between a correct statement and an incorrect one. Notice also that any IEEE 754 number can be (exactly!) printed with a finite number of decimal digits. Finally, notice that writing an algorithm to print them correctly is not rocket science. Hence my astonishment when Tim showed me that the C standard decided, instead, to allow blatant violations of the principle of least astonishment :-) All the best, Roberto -- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara AT cs DOT unipr DOT it -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/