]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SquidMath.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / SquidMath.cc
1 #include "squid.h"
2 #include "SquidMath.h"
3
4 int
5 Math::intPercent(const int a, const int b)
6 {
7 return b ? ((int) (100.0 * a / b + 0.5)) : 0;
8 }
9
10 int64_t
11 Math::int64Percent(const int64_t a, const int64_t b)
12 {
13 return b ? ((int64_t) (100.0 * a / b + 0.5)) : 0;
14 }
15
16 double
17 Math::doublePercent(const double a, const double b)
18 {
19 return b ? (100.0 * a / b) : 0.0;
20 }
21
22 double
23 Math::doubleAverage(const double cur, const double newD, int N, const int max)
24 {
25 if (N > max)
26 N = max;
27
28 return (cur * (N - 1.0) + newD) / N;
29 }
30
31 int
32 Math::intAverage(const int cur, const int newI, int n, const int max)
33 {
34 if (n > max)
35 n = max;
36
37 return (cur * (n - 1) + newI) / n;
38 }