From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16973 invoked by alias); 2 Jul 2002 06:24:32 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 16960 invoked from network); 2 Jul 2002 06:24:27 -0000 Received: from unknown (HELO junk.nocrew.org) (213.242.147.30) by sources.redhat.com with SMTP; 2 Jul 2002 06:24:27 -0000 Received: from lars by junk.nocrew.org with local (Exim 3.31 #1 (Debian)) for gcc@gcc.gnu.org id 17PH5O-0001gw-00; Tue, 02 Jul 2002 08:24:26 +0200 To: gcc@gcc.gnu.org Subject: Re: Comparing doubles References: <8565zziaat.fsf@junk.nocrew.org> From: Lars Brinkhoff Organization: nocrew Date: Mon, 01 Jul 2002 23:24:00 -0000 In-Reply-To: Message-ID: <85sn32hckl.fsf@junk.nocrew.org> User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-07/txt/msg00054.txt.bz2 > Lars Brinkhoff writes: > > would it be acceptable for a GCC back end to compare two doubles > > by subtracting them, converting the result to float, and then > > compare the result against zero? Geoff Keating writes: > If you define __STDC_IEC_559__, no. That is now the case. > Otherwise, you can do whatever you like, although it might give a > less-than-useful FP implementation. Alan Lehotsky writes: > I don't quite remember what PDP10 doubles were like, but if you > don't have NANs, then using subtraction is probably a viable > approach. PDP-10 doubles are just floats with one more word of mantissa. There are no NANs (nor infinities or -0). Floating-point numbers have the property that (when normalized) they can be compared using the normal integer-comparing instructions. > The problem with using subtract is that you may [...] have an > undetected underflow interpreted as equality when it isn't. That is understood. Mark Hahn writes: > calling the inputs "double" would seem extremely dishonest then... Somewhat devious, yes, but not extremely dishonest, really? -- Lars Brinkhoff http://lars.nocrew.org/ Linux, GCC, PDP-10, Brinkhoff Consulting http://www.brinkhoff.se/ HTTP programming