From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 783571F466 for ; Tue, 28 Jan 2020 02:08:44 +0000 (UTC) Received: from localhost ([::1]:53194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwGJ1-0000Wx-7d for normalperson@yhbt.net; Mon, 27 Jan 2020 21:08:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35288) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwGIw-0000Wr-K3 for bug-gnulib@gnu.org; Mon, 27 Jan 2020 21:08:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwGIv-0006hY-Jw for bug-gnulib@gnu.org; Mon, 27 Jan 2020 21:08:38 -0500 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::3]:34424) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iwGIu-0006gE-Te for bug-gnulib@gnu.org; Mon, 27 Jan 2020 21:08:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1580177312; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=YX7//zYGBnTR8PYdY+JTfF32fr2W7Bbc/nZPaFvh40A=; b=EKiPokt3RxeLcO7vRBrBippG+x62wyph63N5XFX+kR7clWUCAaTP3qpDCklpKvqo73 ka+6zKskHJqLrl4BF/UHYys5YHSa1fi7ZJOihtAORp6vrlR934QzFkDtljSi/s3pMbVw Oc30hn1tHqoC4eH3muLkK/J6CMYzmv6kWYEzaIYpGtoKw4cvqhT2FwPQ9HV/GMnFzG1D KmX3/9B/Nu+cdJ3GBtMoNyzunM3vuTtUGSAGdBYsbIXx7QcFmfP483fEoOj7cn73YmTY dmL4htrQx9wdESqJWvThGsMaRFpYDSZ2z9k2WeCoxw7GTl5hEBJeyjW7mhARqO7ygJsj k9tQ== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.1.7 DYNA|AUTH) with ESMTPSA id d0b1daw0S28UIWM (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Tue, 28 Jan 2020 03:08:30 +0100 (CET) From: Bruno Haible To: Paul Eggert Subject: Re: clang-10 warning in hash.c Date: Tue, 28 Jan 2020 03:08:29 +0100 Message-ID: <1889700.0aJY4gUBOZ@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <2438806.b7suTYUyVx@omega> References: <2438806.b7suTYUyVx@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::3 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim =?ISO-8859-1?Q?R=FChsen?= , bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" I wrote: > And I dislike it because the transformation is correct only if > (float) SIZE_MAX >= SIZE_MAX. In the other case, > (float) SIZE_MAX < SIZE_MAX, the transformation is incorrect > [think of the particular value new_candidate = (float) SIZE_MAX]. Ouch, I was assuming that the comparison should be done according to exact mathematical value (infinite precision), like it is in Common Lisp. It's not the case in C! The integer gets rounded to the floating-point type first, leading to surprising results: =============================================================== #include volatile unsigned long long pi; volatile long long ni; volatile float pf = 65536.0f * 65536.0f * 65536.0f * 65536.0f; volatile float nf = - 32768.0f * 65536.0f; int compare1 (void) { return pi <= pf; } int compare1ld (void) { return (long double) pi <= (long double) pf; } int compare2 (void) { return ni <= nf; } int compare2d (void) { return (double) ni <= (double) nf; } int main () { pi = 0xFFFFFFFFFFFFFFFFUL; printf ("%d %d\n", compare1 (), compare1ld ()); ni = -0x7FFFFFFF; printf ("%d %d\n", compare2 (), compare2d ()); } =============================================================== Produces: 1 1 1 0 And with '<' instead of '<=': =============================================================== #include volatile unsigned long long pi; volatile long long ni; volatile float pf = 65536.0f * 65536.0f * 65536.0f * 65536.0f; volatile float nf = - 32768.0f * 65536.0f; int compare1 (void) { return pi < pf; } int compare1ld (void) { return (long double) pi < (long double) pf; } int compare2 (void) { return ni < nf; } int compare2d (void) { return (double) ni < (double) nf; } int main () { pi = 0xFFFFFFFFFFFFFFFFUL; printf ("%d %d\n", compare1 (), compare1ld ()); ni = -0x7FFFFFFF; printf ("%d %d\n", compare2 (), compare2d ()); } =============================================================== Produces: 0 1 0 0 Bruno