Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
percentages.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#pragma once
5
6#include "../../namespaces.h"
7
8#include <cassert>
9
11
12 /*!
13 * Returns the percentage of \amount over \a total.
14 *
15 * \a amount needs to be greater or equal to zero and \a total
16 * needs to be greater than zero.
17 */
18 inline double percent_of(double amount, double total) {
19 assert(amount >= 0.0);
20 assert(total > 0.0);
21
22 return (amount / total) * 100.0;
23 }
24
25 /*!
26 * Given the cardinality of a set, returns the percentage
27 * probability that applied to every element of the set generates
28 * a uniform distribution.
29 */
30 inline double uniform_probability(std::size_t cardinality) {
31 assert(cardinality > 0);
32
33 return (100.0 / static_cast<double>(cardinality));
34 }
35
36 /*!
37 * Returns a percentage probability that is equal to \a
38 * probability.
39 *
40 * \a probability must be in the range [0.0, 1.0]
41 */
42 inline double probability_to_percentage(double probability) {
43 assert(probability >= 0.0);
44 assert(probability <= 1.0);
45
46 return probability * 100.0;
47 }
48
49} // end QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE
double percent_of(double amount, double total)
Returns the percentage of \amount over total.
Definition percentages.h:18
double uniform_probability(std::size_t cardinality)
Given the cardinality of a set, returns the percentage probability that applied to every element of t...
Definition percentages.h:30
double probability_to_percentage(double probability)
Returns a percentage probability that is equal to probability.
Definition percentages.h:42
#define QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE
Definition namespaces.h:14
#define assert