X-Spam-Check-By: sourceware.org
X-ORBL: [63.192.140.4]
Message-ID: <4408C140.9030100@myrealbox.com>
Date: Fri, 03 Mar 2006 14:20:48 -0800
From: Tim Prince <tprince@myrealbox.com>
Reply-To: tprince@computer.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921
MIME-Version: 1.0
To: Roberto Bagnara <bagnara@cs.unipr.it>
CC: cygwin@cygwin.com,
   "The Parma Polyhedra Library developers' list" <ppl-devel@cs.unipr.it>
Subject: Re: Precision of doubles and stdio
References: <4408B886.5010209@cs.unipr.it>
In-Reply-To: <4408B886.5010209@cs.unipr.it>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Roberto Bagnara wrote:
> 
> Hi there,
> 
> the following little program
> 
> #include <stdio.h>
> 
> int main() {
>   double d;
>   scanf("%lf", &d);
>   printf("%.1000g\n", d);
>   return 0;
> }
> 
> does this on Linux/i686
> 
> $ gcc -W -Wall in.c
> $ a.out
> 70.9
> 70.900000000000005684341886080801486968994140625
> 
> and does the following under Cygwin on the same machine:
> 
> roberto@quark /tmp
> $ gcc -W -Wall in.c
> 
> roberto@quark /tmp
> $ ./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.
If you haven't gone out of your way to install similar printf() support 
libraries on cygwin and linux, they will definitely not be the same.  My 
past reading of various relevant documents convinced me that digits 
beyond the 17th in formatting of doubles are not required by any 
standard to be consistent between implementations.  They have no useful 
function, as 17 digits are sufficient to determine uniquely the 
corresponding binary value in IEEE 754 format.

--
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/

