From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36801 invoked by alias); 20 Sep 2018 15:05:55 -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 36784 invoked by uid 89); 20 Sep 2018 15:05:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=regarded, contrary, UD:tst.c, tst.c 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 15:05:53 +0000 Received: from vlefevre by cventin.lip.ens-lyon.fr with local (Exim 4.91) (envelope-from ) id 1g30Wc-0001ey-On; Thu, 20 Sep 2018 17:05:50 +0200 Date: Thu, 20 Sep 2018 15:05:00 -0000 From: Vincent Lefevre To: Andrew Haley , Neha Gowda , gcc-help@gcc.gnu.org Subject: Re: Should rand() return a RAND_MAX value for 32 bit target? Message-ID: <20180920150550.GA4852@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> <20180920144238.GB24856@cventin.lip.ens-lyon.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180920144238.GB24856@cventin.lip.ens-lyon.fr> 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/msg00062.txt.bz2 Actually, there may be a bug with -m32: #include #include int main (void) { float f = 2147483646; printf ("FLT_EVAL_METHOD = %d\n", (int) FLT_EVAL_METHOD); if (f == 2147483647) { printf("%.20g\n", (double) f); } return 0; } $ gcc -std=c99 -m32 -O tst.c -o tst $ ./tst FLT_EVAL_METHOD = 2 2147483648 Since FLT_EVAL_METHOD = 2, float_t is long double, thus shouldn't 2147483647 be converted to long double directly (as f is regarded as an operand of type long double), so that the result of the equality test should be false? The C standard says for FLT_EVAL_METHOD = 2: "evaluate all operations and constants to the range and precision of the long double type". ^^^^^^^^^^^^^ Converting f first to float is contrary to the idea behind FLT_EVAL_METHOD = 2, which is to avoid loss of precision in intermediate operations. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)