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]

wrap around problem for "double"?


Hi,

  I was wondering why when "double" is assigned into a "short int" in cygwin 1.7, it doesn't wrap around correctly, eg:

main () 
{
  short int x;
  int y = -63757;
  double y2 = -63757;
  x = y; // wraps around correctly going from int to short int
  printf("%d (should be 1779)\n",x);
  x = y2; // but just truncates when going from double to short int
  printf("%d (THIS DOES NOT WRAP AROUND CORRECTLY, should be 1779)\n",x);
}

The output is this:

1779 (should be 1779)
-32768 (THIS DOES NOT WRAP AROUND CORRECTLY, should be 1779)

Instead of wrapping around for the short int, it just truncates it at -32768 which is not the behavior I was expecting.  It doesn't work like this either on linux or solaris operating system.  Also, when assigning a double into an int, it will just truncates and not wrap around.  Is this a bug and if so, is there a newer version of Cygwin that fixes this bug?

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


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