]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SquidMath.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / SquidMath.cc
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
bbc27441
AJ
3 *
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.
7 */
8
f7f3304a 9#include "squid.h"
a98bcbee
AJ
10#include "SquidMath.h"
11
12int
13Math::intPercent(const int a, const int b)
14{
15 return b ? ((int) (100.0 * a / b + 0.5)) : 0;
16}
17
12e11a5c
AJ
18int64_t
19Math::int64Percent(const int64_t a, const int64_t b)
20{
21 return b ? ((int64_t) (100.0 * a / b + 0.5)) : 0;
22}
23
a98bcbee
AJ
24double
25Math::doublePercent(const double a, const double b)
26{
27 return b ? (100.0 * a / b) : 0.0;
28}
29
30double
31Math::doubleAverage(const double cur, const double newD, int N, const int max)
32{
33 if (N > max)
34 N = max;
35
36 return (cur * (N - 1.0) + newD) / N;
37}
38
39int
40Math::intAverage(const int cur, const int newI, int n, const int max)
41{
42 if (n > max)
43 n = max;
44
45 return (cur * (n - 1) + newI) / n;
46}
f53969cc 47