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: wrap around problem for "double"?

Phan, Linh H (343H) wrote:
> Hi,
> 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#

> 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:
Unsubscribe info:

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