It looks to me like you are rounding on each iteration of the for-loop:

+    for (i = 0; rate > 9999 && i <= 3; i++) {
+        rtmp = rate / 1000;
+        if (rtmp < 9999)
+            rtmp += (rate % 1000) / 500;
+        rate = rtmp;
+    }

Am I missing something?

I'll post my patch on Tuesday.

Yes, I understand that systat can display only 4 digits for BW.
That's 5 digits with my guard digit, which is shifted out (and not displayed) 
at the end.
So, with the guard digit, 6 digits is too many.


--------------------------------------------
On Sun, 5/14/17, Mike Belopuhov <m...@belopuhov.com> wrote:

 Subject: Re: pf queue definition: bandwidth resolution problem
 To: "Carl Mascott" <cmasc...@yahoo.com>
 Cc: tech@openbsd.org, t...@openbsd.org
 Date: Sunday, May 14, 2017, 4:05 PM
 
 On Sun, May 14, 2017 at 19:48 +0000, Carl
 Mascott wrote:
 > I have a suggestion RE
 your pftop.c patch.  You are rounding
 >
 multiple times, after each scale operation.  This is known
 as
 > rounding the intermediate results of
 a calculation and degrades
 > accuracy. 
 If you're not familiar with the issue do a Google
 search
 > on rounding intermediate.
 > 
 
 I round
 only once, that's what I've explained in my
 mail.
 
 > I suggest assigning the
 pf rate to an unsigned long and multiplying by 10.
 > This makes the LSD a guard digit.
 > After all scaling, round once (if guard
 digit >= 5 then add 10).
 > Yes, this
 may require one more scaling operation if it rounds up to 6
 digits (including guard digit).
 > At the
 very end divide by 10.
 > Note: This is
 essentially fixed point arithmetic with one decimal
 digit.
 > 
 > I modified
 pftop.c v1.37 to do this earlier today.
 >
 It was kind of tricky.
 > I need to see if
 it still looks OK on Tuesday (I'm busy Monday).
 > Let me know if you want a patch then.
 > I won't have actually tested it,
 though, so it's highly likely to have bugs.
 > You might be better off writing your own
 (and then perhaps comparing to mine).
 >
 
 > RE my email client: It's Yahoo
 webmail -- nothing I can do about it.
 > 
 
 pftop in
 systat can only display 4 digits and 1 unit symbol
 so you can't display all digits of your
 bandwidth spec.
 But please by all means,
 send your diff and I'll take a look at it.
 
 

Reply via email to