From owner-freebsd-toolchain@freebsd.org Mon Mar 14 01:53:12 2016 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D27B3AD0780 for ; Mon, 14 Mar 2016 01:53:12 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id B95CBECD; Mon, 14 Mar 2016 01:53:12 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id u2E1rBji028274 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 13 Mar 2016 18:53:11 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id u2E1rBdZ028273; Sun, 13 Mar 2016 18:53:11 -0700 (PDT) (envelope-from sgk) Date: Sun, 13 Mar 2016 18:53:11 -0700 From: Steve Kargl To: Dimitry Andric Cc: freebsd-toolchain@freebsd.org Subject: Re: clang gets numerical underflow wrong, please fix. Message-ID: <20160314015311.GA28237@troutmask.apl.washington.edu> References: <20160313182521.GA25361@troutmask.apl.washington.edu> <74970883-FE44-47C0-BDA0-92DB0723398A@FreeBSD.org> <20160313201004.GA26343@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2016 01:53:12 -0000 On Mon, Mar 14, 2016 at 01:02:20AM +0100, Dimitry Andric wrote: > > $ gcc -O overflow-iter.c -o overflow-iter-gcc -lm > $ ./overflow-iter-gcc > FE_OVERFLOW: x = inf after 1024 iterations > $ gcc -O2 overflow-iter.c -o overflow-iter-gcc -lm > $ ./overflow-iter-gcc > FE_OVERFLOW: x = inf after 16384 iterations > Change the program to #include #include int main(void) { int i; float x = 1.f; i = 0; feclearexcept(FE_ALL_EXCEPT); do { x *= 2; i++; printf("%d %e\n", i, x); } while(!fetestexcept(FE_OVERFLOW)); if (fetestexcept(FE_OVERFLOW)) printf("FE_UNDERFLOW: "); printf("x = %e after %d iterations\n", x, i); return 0; } You'll get a bunch of invalid output before the OVERFLOW. % cc -O -o z b.c -lm && ./z | tail 1016 7.022239e+305 <-- not a valid float 1017 1.404448e+306 <-- not a valid float 1018 2.808896e+306 <-- not a valid float 1019 5.617791e+306 <-- not a valid float 1020 1.123558e+307 <-- not a valid float 1021 2.247116e+307 <-- not a valid float 1022 4.494233e+307 <-- not a valid float 1023 8.988466e+307 <-- not a valid float 1024 inf FE_UNDERFLOW: x = inf after 1024 iterations Clang is broken with or without #pragma FENV_ACCESS "on". -- Steve