lkml.org 
[lkml]   [2010]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v7 3/3] nl80211/mac80211: Report signal average
On Fri, Nov 19, 2010 at 06:07:05PM +0900, Bruno Randolf wrote:
> Hmm, maybe I suck in mathemathics, but I don't see a way to do that given the
> formula:
>
> (((internal * (weight - 1)) + (val * factor)) / weight

I was thinking something along the lines of:

round = (1 << n) - 1;
(((internal * (weight - 1) + round) >> n) + val) * ((1 << n) / weight)

where (1 << n) is the factor and ((1 << n) / weight) can be precomputed.
If you think about it, this is just reciprocal multiplication in fixed-
point math with n bits of decimal resolution.

The problem is the shift of the older terms introduces roundoff error, but
there are some tricks you can do to maintain bounded error, e.g. shifting
by some smaller factor of n and scaling other terms -- in the limit you
reinvent floating point and then it's slower than division :)

--
Bob Copeland %% www.bobcopeland.com



\
 
 \ /
  Last update: 2010-11-20 00:17    [W:0.185 / U:0.268 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site