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
26
27
28
29
30
31
32
33
34
35
36
#pragma once


#include <cstdint><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <limits><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.


#include "numeric/limits.hpp"
#include "numeric/arithmetic.hpp"


namespace uni {


template<class T>
inline std::int32_t compare(const T x, const T y, const T tolerance) {
    if(x > y + tolerance) return 1;
    if(y > x + tolerance) return -1;
    return 0;
}


template<class T>
inline std::int32_t compare(const T x, const T y = 0) {
    if constexpr(std::is_floating_point_v<T>) {
        return compare(x, y, max(1, x, y) * numeric_limits<T>::arithmetic_epsilon());
    }
    else {
        if(x > y) return 1;
        if(x < y) return -1;
        return 0;
    }
}


} // namespace uni