]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SquidMath.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "SquidMath.h"
13 Math::intPercent(const int a
, const int b
)
15 return b
? ((int) (100.0 * a
/ b
+ 0.5)) : 0;
19 Math::int64Percent(const int64_t a
, const int64_t b
)
21 return b
? ((int64_t) (100.0 * a
/ b
+ 0.5)) : 0;
25 Math::doublePercent(const double a
, const double b
)
27 return b
? (100.0 * a
/ b
) : 0.0;
31 Math::doubleAverage(const double cur
, const double newD
, int N
, const int max
)
36 return (cur
* (N
- 1.0) + newD
) / N
;
40 Math::intAverage(const int cur
, const int newI
, int n
, const int max
)
45 return (cur
* (n
- 1) + newI
) / n
;