Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
rounding.hh
Go to the documentation of this file.
1/*
2 * Scroom - Generic viewer for 2D data
3 * Copyright (C) 2009-2026 Kees-Jan Dijkzeul
4 *
5 * SPDX-License-Identifier: LGPL-2.1
6 */
7
8#pragma once
9
10#include <cmath>
11
12inline double rounded_divide_by(double value, double factor) { return std::round(value / factor); }
13inline double ceiled_divide_by(double value, double factor) { return std::ceil(value / factor); }
14inline double floored_divide_by(double value, double factor) { return std::floor(value / factor); }
15
16inline int rounded_divide_by(int value, int factor)
17{
18 return static_cast<int>(rounded_divide_by(static_cast<double>(value), static_cast<double>(factor)));
19}
20
21inline int ceiled_divide_by(int value, int factor)
22{
23 return static_cast<int>(ceiled_divide_by(static_cast<double>(value), static_cast<double>(factor)));
24}
25
26inline int floored_divide_by(int value, int factor)
27{
28 return static_cast<int>(floored_divide_by(static_cast<double>(value), static_cast<double>(factor)));
29}
30
31template <typename T>
33{
34 return factor * rounded_divide_by(value, factor);
35}
36
37template <typename T>
39{
40 return factor * ceiled_divide_by(value, factor);
41}
42
43template <typename T>
45{
46 return factor * floored_divide_by(value, factor);
47}
const uint8_t value
Definition blob-tests.cc:114
double floored_divide_by(double value, double factor)
Definition rounding.hh:14
T round_up_to_multiple_of(T value, T factor)
Definition rounding.hh:38
double ceiled_divide_by(double value, double factor)
Definition rounding.hh:13
T round_to_multiple_of(T value, T factor)
Definition rounding.hh:32
T round_down_to_multiple_of(T value, T factor)
Definition rounding.hh:44
double rounded_divide_by(double value, double factor)
Definition rounding.hh:12