summaryrefslogtreecommitdiffhomepage
path: root/compat/math.hpp
blob: 1387324efc4ff2edfb6c640eed3f3a25648f6eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once

#include "macros.hpp"

#include <cmath>
#include <type_traits>

template<typename t>
inline auto iround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, int>
{
    return (int)std::round(val);
}

template<typename t>
inline auto uround(t val) -> std::enable_if_t<std::is_floating_point_v<remove_cvref_t<t>>, unsigned>
{
    return (unsigned)std::fmax(0, std::round(val));
}

template <typename t>
force_inline
constexpr int signum(const t& x)
{
    return x < t{0} ? -1 : 1;
}