This is the mail archive of the
mailing list for the Cygwin project.
Re: wrap around problem for "double"?
Phan, Linh H (343H) wrote:
> I was wondering why when "double" is assigned into a "short int" in cygwin
> 1.7, it doesn't wrap around correctly,
A double is a floating-point type, not an integer. Your program is
incorrect; it invokes undefined behaviour per n1256#22.214.171.124.1:
> When a finite value of real floating type is converted to an integer type
> other than _Bool, the fractional part is discarded (i.e., the value is
> truncated toward zero). If the value of the integral part cannot be
> represented by the integer type, the behavior is undefined.
So, you can't do that. Whether it wraps, truncates, throws a floating-point
exception, or returns a random number, is entirely unpredictable and
system-dependent; the way you expect it to behave is just the way it happens
to behave by chance on the systems that you've tested it on, not how it is
supposed to behave by design.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple