Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Dec 2011 00:53:11 +0000
From:      Igor Mozolevsky <mozolevsky@gmail.com>
To:        Adrian Chadd <adrian@freebsd.org>
Cc:        Alexander Best <arundel@freebsd.org>, freebsd-wireless@freebsd.org
Subject:   Re: comparing floating points via "==" or "!="
Message-ID:  <CADWvR2ivioaRgmcWT89AwMgE3=e-N5Vm4djLq=OUT6GVtqEy9Q@mail.gmail.com>
In-Reply-To: <CADWvR2hAohYysntaK_UJcwU10%2Bvy4pDrpSnj-DU%2BKphZLW6Tdw@mail.gmail.com>
References:  <20111130224422.GA36424@freebsd.org> <CADWvR2herXkcMaZXFKm_ALBXnVFDhRCNZ-9%2B-MwHVx5XJPG4AA@mail.gmail.com> <20111201000243.GB44877@freebsd.org> <CADWvR2irEU0ANHNG4mvC1voVP6Y3YMTQxs5d35o5SbBTJ8JyfQ@mail.gmail.com> <20111201001158.GA48051@freebsd.org> <CADWvR2iUB4mDFuwbWzqe6bnjShTZEQzQ-ubAx8h7yqGwjcUHKA@mail.gmail.com> <20111201003938.GA52503@freebsd.org> <CAJ-Vmon4Fn4RAMhHS6skpsy2Lst3XUYXsENSCr0SCQFjQH6c6w@mail.gmail.com> <CADWvR2hAohYysntaK_UJcwU10%2Bvy4pDrpSnj-DU%2BKphZLW6Tdw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 1 December 2011 00:48, Igor Mozolevsky <mozolevsky@gmail.com> wrote:
> On 1 December 2011 00:43, Adrian Chadd <adrian@freebsd.org> 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 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"


(((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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CADWvR2ivioaRgmcWT89AwMgE3=e-N5Vm4djLq=OUT6GVtqEy9Q>