cMHN 1.2
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<IsValue 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(IsSame<T, Float<64>>)
48 {
49 return 1e-12;
50 }
51 if constexpr(IsSame<T, Float<32>>)
52 {
53 return 1e-5f;
54 }
55
56 return zero<T>();
57 }
58 };
59
60 template<>
61 struct NumericLimits<Float<16>>
62 {
63 static constexpr Size digits()
64 {
65 return 7;
66 }
67
68 static constexpr Float<16> min()
69 {
70 return BFloat16::FromRepresentation(0x0080);
71 }
72
73 static constexpr Float<16> max()
74 {
75 return BFloat16::FromRepresentation(0x7F7F);
76 }
77
78 static constexpr Float<16> lowest()
79 {
80 return BFloat16::FromRepresentation(0xFF7F);
81 }
82
83 static constexpr Float<16> epsilon()
84 {
85 return BFloat16::FromRepresentation(0x3C00);
86 }
87
88 static constexpr Float<16> tolerance()
89 {
90 return BFloat16::FromRepresentation(0x3C24);
91 }
92 };
93}
94#endif // pRC_CORE_VALUE_LIMITS_H
static constexpr auto FromRepresentation(Representation const rep)
Definition bfloat16.hpp:24
Definition value.hpp:12
Conditional< W==16, BFloat16, Conditional< W==32, float, Conditional< W==64, double, Undefined > > > Fundamental
Definition float.hpp:23
Definition concepts.hpp:28
Definition cholesky.hpp:10
std::size_t Size
Definition basics.hpp:31
static constexpr auto zero()
Definition zero.hpp:12
static constexpr Float< 16 > epsilon()
Definition limits.hpp:83
static constexpr Float< 16 > lowest()
Definition limits.hpp:78
static constexpr Size digits()
Definition limits.hpp:63
static constexpr Float< 16 > tolerance()
Definition limits.hpp:88
static constexpr Float< 16 > max()
Definition limits.hpp:73
static constexpr Float< 16 > min()
Definition limits.hpp:68
static constexpr T min()
Definition limits.hpp:25
static constexpr T epsilon()
Definition limits.hpp:40
static constexpr T lowest()
Definition limits.hpp:35
static constexpr Size digits()
Definition limits.hpp:20
static constexpr T max()
Definition limits.hpp:30
static constexpr T tolerance()
Definition limits.hpp:45
Definition limits.hpp:13