ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
uniform.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2026 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#pragma once
19
21
22#include <cinttypes>
23#include <limits>
24
25namespace Utils {
26/**
27 * @brief Uniformly map unsigned integer to double.
28 *
29 * This maps a unsigned integer to the double interval
30 * (0., 1.], where 0 is mapped to the smallest representable
31 * value larger than 0., and the maximal integer value is
32 * mapped to 1.
33 *
34 * @param in Unsigned integer value
35 * @return Mapped floating point value.
36 */
37constexpr DEVICE_QUALIFIER inline double uniform(uint64_t in) {
38 auto constexpr const max = std::numeric_limits<uint64_t>::max();
39 auto constexpr const fac = 1. / (static_cast<double>(max) + 1.);
40
41 return fac * static_cast<double>(in) + 0.5 * fac;
42}
43
44} // namespace Utils
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
#define DEVICE_QUALIFIER
constexpr DEVICE_QUALIFIER double uniform(uint64_t in)
Uniformly map unsigned integer to double.
Definition uniform.hpp:37