Date: Thu, 1 Dec 2011 00:39:38 +0000 From: Alexander Best <arundel@freebsd.org> To: Igor Mozolevsky <mozolevsky@gmail.com> Cc: freebsd-wireless@freebsd.org Subject: Re: comparing floating points via "==" or "!=" Message-ID: <20111201003938.GA52503@freebsd.org> In-Reply-To: <CADWvR2iUB4mDFuwbWzqe6bnjShTZEQzQ-ubAx8h7yqGwjcUHKA@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>
next in thread | previous in thread | raw e-mail | index | archive | help
--8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu Dec 1 11, Igor Mozolevsky wrote: > On 1 December 2011 00:11, Alexander Best <arundel@freebsd.org> wrote: > > > i sorry. since sys/dev/ath/ath_rate/sample/tx_schedules.h also handles a lot > > of integer values, i thought you referred to abs(3), because you saw also > > some issues with the integer computations in that file. so i thought you were > > referring to yet another issue in that file. > > Oh, I see! No, I was referring to a generic |a-b| expression, not > abs(3) specifically. Retrospectively, using |a-b| would've been better > :-) so wrapping fabs(3) inside a macro, like in the following example might work. cheers. alex ps: just a 60 second hack. ;) > > Cheers, > > -- > Igor --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tx_schedules.h.diff" Index: sys/dev/ath/ath_rate/sample/tx_schedules.h =================================================================== --- sys/dev/ath/ath_rate/sample/tx_schedules.h (revision 228164) +++ sys/dev/ath/ath_rate/sample/tx_schedules.h (working copy) @@ -40,6 +40,11 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#define TOLERANCE 0.00001 + +#define F(_r1, _r2)\ + ((fabs(_r1-_r2) < TOLLERANCE) ? 1 : 0) + #define A(_r) \ (((_r) == 6) ? 0 : (((_r) == 9) ? 1 : (((_r) == 12) ? 2 : \ (((_r) == 18) ? 3 : (((_r) == 24) ? 4 : (((_r) == 36) ? 5 : \ @@ -56,7 +61,7 @@ }; #define NA1(_r) \ - (((_r) == 6.5) ? 8 : (((_r) == 13) ? 9 : (((_r) == 19.5)? 10 : \ + ((F(_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)))))))) #define NA2(_r) \ --8t9RHnE3ZwKMSgU+--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111201003938.GA52503>