cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
limits.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_LIMITS_H
4#define pRC_CORE_VALUE_LIMITS_H
5
10
11namespace pRC
12{
13 template<class T>
15 {
16 private:
17 using F = typename T::Fundamental;
18
19 public:
20 static constexpr Size digits()
21 {
22 return std::numeric_limits<F>::digits;
23 }
24
25 static constexpr T min()
26 {
27 return std::numeric_limits<F>::min();
28 }
29
30 static constexpr T max()
31 {
32 return std::numeric_limits<F>::max();
33 }
34
35 static constexpr T lowest()
36 {
37 return std::numeric_limits<F>::lowest();
38 }
39
40 static constexpr T epsilon()
41 {
42 return std::numeric_limits<F>::epsilon();
43 }
44
45 static constexpr T tolerance()
46 {
47 if constexpr(IsFloat<T>())
48 {
49 if constexpr(typename T::Width() == 64)
50 {
51 return 1e-12;
52 }
53 if constexpr(typename T::Width() == 32)
54 {
55 return 1e-5f;
56 }
57 }
58 else
59 {
60 return zero<T>();
61 }
62 }
63 };
64
65 template<>
66 struct NumericLimits<Float<16>>
67 {
68 static constexpr Size digits()
69 {
70 return 7;
71 }
72
73 static constexpr Float<16> min()
74 {
75 return BFloat16::FromRepresentation(0x0080);
76 }
77
78 static constexpr Float<16> max()
79 {
80 return BFloat16::FromRepresentation(0x7F7F);
81 }
82
83 static constexpr Float<16> lowest()
84 {
85 return BFloat16::FromRepresentation(0xFF7F);
86 }
87
88 static constexpr Float<16> epsilon()
89 {
90 return BFloat16::FromRepresentation(0x3C00);
91 }
92
93 static constexpr Float<16> tolerance()
94 {
95 return BFloat16::FromRepresentation(0x3C24);
96 }
97 };
98}
99#endif // pRC_CORE_VALUE_LIMITS_H
static constexpr auto FromRepresentation(Representation const rep)
Definition bfloat16.hpp:26
pRC::Constant< Size, W > Width
Definition float.hpp:39
Conditional< IsSatisfied<(W==16)>, BFloat16, Conditional< IsSatisfied<(W==32)>, float, Conditional< IsSatisfied<(W==64)>, double, Undefined > > > Fundamental
Definition float.hpp:24
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
std::size_t Size
Definition type_traits.hpp:20
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Any< IsFloat< T >, IsInteger< T > > IsValue
Definition type_traits.hpp:72
Definition type_traits.hpp:16
static constexpr Float< 16 > epsilon()
Definition limits.hpp:88
static constexpr Float< 16 > lowest()
Definition limits.hpp:83
static constexpr Size digits()
Definition limits.hpp:68
static constexpr Float< 16 > tolerance()
Definition limits.hpp:93
static constexpr Float< 16 > max()
Definition limits.hpp:78
static constexpr Float< 16 > min()
Definition limits.hpp:73
static constexpr T max()
Definition limits.hpp:30
static constexpr T min()
Definition limits.hpp:25
static constexpr Size digits()
Definition limits.hpp:20
static constexpr T epsilon()
Definition limits.hpp:40
static constexpr T lowest()
Definition limits.hpp:35
static constexpr T tolerance()
Definition limits.hpp:45
Definition limits.hpp:13