From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102827 invoked by alias); 20 Sep 2018 14:42:49 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 102499 invoked by uid 89); 20 Sep 2018 14:42:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=1.7 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=Blog, H*f:AEAs, H*f:Rc_xagiud, rand_max X-HELO: cventin.lip.ens-lyon.fr Received: from cventin.lip.ens-lyon.fr (HELO cventin.lip.ens-lyon.fr) (140.77.13.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Sep 2018 14:42:43 +0000 Received: from vlefevre by cventin.lip.ens-lyon.fr with local (Exim 4.91) (envelope-from ) id 1g30AA-0001Y4-7x; Thu, 20 Sep 2018 16:42:38 +0200 Date: Thu, 20 Sep 2018 14:42:00 -0000 From: Vincent Lefevre To: Andrew Haley Cc: Neha Gowda , gcc-help@gcc.gnu.org Subject: Re: Should rand() return a RAND_MAX value for 32 bit target? Message-ID: <20180920144238.GB24856@cventin.lip.ens-lyon.fr> Mail-Followup-To: Andrew Haley , Neha Gowda , gcc-help@gcc.gnu.org References: <9194d2a2-74c0-2d51-c4b5-433d2744cd43@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9194d2a2-74c0-2d51-c4b5-433d2744cd43@redhat.com> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.10.1+96 (4350694b) vl-108074 (2018-09-18) X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00061.txt.bz2 On 2018-09-18 14:46:24 +0100, Andrew Haley wrote: > On 09/18/2018 01:22 PM, Neha Gowda wrote: > > Can you please let me know if its the expected behavior or some bug? > > First consider the value of (float)RAND_MAX. Then please consider if > using -ffloat-store will make any difference to your program and then > you may be enlightened. If not, please come back and ask again. No, the program is so buggy that -ffloat-store does not solve the problem because there is rounding in the == expression. As a short example: #include int main (void) { float f = 2147483646; if (f == 2147483647) { printf("%.20g\n", (double) f); } return 0; } outputs 2147483648 because the == is done on float. Thus, from the original program, you cannot deduce anything. And BTW, don't try to cast f to int, that's undefined behavior here. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)