Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
uniform.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2022 The ESPResSo project
3 *
4 * ESPResSo is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * ESPResSo is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef UTILS_UNIFORM_HPP
19#define UTILS_UNIFORM_HPP
20
21#include <cinttypes>
22#include <limits>
23
24namespace Utils {
25/**
26 * @brief Uniformly map unsigned integer to double.
27 *
28 * This maps a unsigned integer to the double interval
29 * (0., 1.], where 0 is mapped to the smallest representable
30 * value larger than 0., and the maximal integer value is
31 * mapped to 1.
32 *
33 * @param in Unsigned integer value
34 * @return Mapped floating point value.
35 */
36constexpr inline double uniform(uint64_t in) {
37 auto constexpr const max = std::numeric_limits<uint64_t>::max();
38 auto constexpr const fac = 1. / (static_cast<double>(max) + 1.);
39
40 return fac * static_cast<double>(in) + 0.5 * fac;
41}
42
43} // namespace Utils
44
45#endif // ESPRESSO_UNIFORM_HPP
constexpr double uniform(uint64_t in)
Uniformly map unsigned integer to double.
Definition uniform.hpp:36