This is the mail archive of the
mailing list for the Cygwin project.
wrap around problem for "double"?
- From: "Phan, Linh H (343H)" <linh dot h dot phan at jpl dot nasa dot gov>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Sat, 19 Dec 2009 22:44:43 -0800
- Subject: wrap around problem for "double"?
I was wondering why when "double" is assigned into a "short int" in cygwin 1.7, it doesn't wrap around correctly, eg:
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
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple