X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4B2DCE64.6020801@gmail.com> Date: Sun, 20 Dec 2009 07:12:36 +0000 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: wrap around problem for "double"? References: <79D001DEDB0DEC47A247B110F3E8668206E59D5F92 AT ALTPHYEMBEVSP30 DOT RES DOT AD DOT JPL> In-Reply-To: <79D001DEDB0DEC47A247B110F3E8668206E59D5F92@ALTPHYEMBEVSP30.RES.AD.JPL> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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#6.3.1.4.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. cheers, DaveK -- 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