delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/05/10:19:05

X-Spam-Check-By: sourceware.org
Message-ID: <440B01D7.6000806@cs.unipr.it>
Date: Sun, 05 Mar 2006 16:20:55 +0100
From: Roberto Bagnara <bagnara AT cs DOT unipr DOT it>
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: cygwin AT cygwin DOT com
Subject: Re: May I suggest the study of...
References: <op DOT s5xzg2qc5o90vo AT orion>
In-Reply-To: <op.s5xzg2qc5o90vo@orion>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

lemkemch AT t-online DOT de wrote:
> Roberto Bagnara wrote:
>>> Tim Prince wrote:
>>> 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 AT quark /tmp
>>>> $ gcc -W -Wall in.c
>>>>
>>>> roberto AT 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() 
>>> supportlibraries on cygwin and linux, they will definitely not be the 
>>> same.  Mypast reading of various relevant documents convinced me that 
>>> digitsbeyond the 17th in formatting of doubles are not required by 
>>> anystandard to be consistent between implementations.  They have no 
>>> usefulfunction, as 17 digits are sufficient to determine uniquely 
>>> thecorresponding binary value in IEEE 754 format.
>>
>> Thank you Tim.  We were unaware of this giant bug in the C standard.
> 
> Bug in the C standard??? May I suggest the study of
> http://docs.sun.com/source/806-3568/ncg_goldberg.html

I know it very well, thanks.  But you are missing the point.

> There is no exact binary representation for
> powers of ten.

So what?  You are again missing the point completely:
you are talking about binary representations for powers
of ten, while the point here is decimal representations
for numbers that are given by an integer times a powers of two.
A binary value in IEEE 754 format is either a special value
or corresponds to one real number.  This real number always
has a finite decimal representation.

BTW: this is 100% off-topic for the Cygwin mailing list.
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019