From owner-freebsd-wireless@FreeBSD.ORG Thu Dec 1 00:53:53 2011 Return-Path: Delivered-To: freebsd-wireless@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C64D3106564A; Thu, 1 Dec 2011 00:53:53 +0000 (UTC) (envelope-from mozolevsky@gmail.com) Received: from mail-gx0-f182.google.com (mail-gx0-f182.google.com [209.85.161.182]) by mx1.freebsd.org (Postfix) with ESMTP id 5A9D28FC15; Thu, 1 Dec 2011 00:53:53 +0000 (UTC) Received: by ggnk5 with SMTP id k5so1978909ggn.13 for ; Wed, 30 Nov 2011 16:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=a5MAnGYUG27npSjavC79moK8WdLYJ4dYOWv6rdI8j7M=; b=q3aA6hKbYh6hvexUBJEEOXJvr/WTbMLF6EyPEOcTH7bS3Ko9ehr2jHhZGoC0xKxd5Q VeOI5+V/FCvhOhX7ffuERFw5zbAIjMnd/MQ7QnSS/0W9FZdQan0A+/R/bVznhnUkN6pM ConUVKd5d4hE0s+WYxXn0LbxRuLGa9zjdcjwg= Received: by 10.68.55.103 with SMTP id r7mr153074pbp.41.1322700832080; Wed, 30 Nov 2011 16:53:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.68.48.5 with HTTP; Wed, 30 Nov 2011 16:53:11 -0800 (PST) In-Reply-To: References: <20111130224422.GA36424@freebsd.org> <20111201000243.GB44877@freebsd.org> <20111201001158.GA48051@freebsd.org> <20111201003938.GA52503@freebsd.org> From: Igor Mozolevsky Date: Thu, 1 Dec 2011 00:53:11 +0000 Message-ID: To: Adrian Chadd Content-Type: text/plain; charset=UTF-8 Cc: Alexander Best , freebsd-wireless@freebsd.org Subject: Re: comparing floating points via "==" or "!=" X-BeenThere: freebsd-wireless@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussions of 802.11 stack, tools device driver development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Dec 2011 00:53:53 -0000 On 1 December 2011 00:48, Igor Mozolevsky wrote: > On 1 December 2011 00:43, Adrian Chadd wrote: >> Erm, these aren't run-time comparisons though, these are done at compile time. Ignoring the late-night PEBKAC: % gcc -E -O2 - #define NA1(_r) \ (((_r) == 6.5) ? 8 : (((_r) == 13) ? 9 : (((_r) == 19.5)? 10 : \ (((_r) == 26) ? 11 : (((_r) == 39) ? 12 : (((_r) == 52) ? 13 : \ (((_r) == 58.5)? 14 : (((_r) == 65) ? 15 : 0)))))))) NA1(7); # 1 "" # 1 "" # 1 "" # 1 "" (((7) == 6.5) ? 8 : (((7) == 13) ? 9 : (((7) == 19.5)? 10 : (((7) == 26) ? 11 : (((7) == 39) ? 12 : (((7) == 52) ? 13 : (((7) == 58.5)? 14 : (((7) == 65) ? 15 : 0)))))))); It is entirely probable that the compiler might try to optimise that out if it knows the value, but then you'd be relying on the compiler knowing how to deal with floating point comparisons... Cheers, -- Igor