This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: May I suggest the study of... 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

and does the following under Cygwin on the same machine:

roberto@quark /tmp
$ gcc -W -Wall in.c

roberto@quark /tmp
$ ./a.exe

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

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,


Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy

-- Unsubscribe info: Problem reports: Documentation: FAQ:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]