www.delorie.com/archives/browse.cgi | search |
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 <dave DOT korn DOT cygwin AT googlemail DOT com> |
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> |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |