From owner-freebsd-wireless@FreeBSD.ORG Thu Dec 1 00:39:39 2011 Return-Path: Delivered-To: freebsd-wireless@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id 59E751065670; Thu, 1 Dec 2011 00:39:38 +0000 (UTC) Date: Thu, 1 Dec 2011 00:39:38 +0000 From: Alexander Best To: Igor Mozolevsky Message-ID: <20111201003938.GA52503@freebsd.org> References: <20111130224422.GA36424@freebsd.org> <20111201000243.GB44877@freebsd.org> <20111201001158.GA48051@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline In-Reply-To: Cc: 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:39:39 -0000 --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 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 __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+--