pRC
multi-purpose Tensor Train library for C++
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{
22 template<class T>
24 {
25 private:
26 using F = typename T::Fundamental;
27
28 public:
29 static constexpr Size digits()
30 {
31 return std::numeric_limits<F>::digits;
32 }
33
34 static constexpr T min()
35 {
36 return std::numeric_limits<F>::min();
37 }
38
39 static constexpr T max()
40 {
41 return std::numeric_limits<F>::max();
42 }
43
44 static constexpr T lowest()
45 {
46 return std::numeric_limits<F>::lowest();
47 }
48
49 static constexpr T epsilon()
50 {
51 return std::numeric_limits<F>::epsilon();
52 }
53
60 static constexpr T tolerance()
61 {
62 if constexpr(IsFloat<T>())
63 {
64 if constexpr(typename T::Width() == 64)
65 {
66 return 1e-12;
67 }
68 if constexpr(typename T::Width() == 32)
69 {
70 return 1e-5f;
71 }
72 }
73 else
74 {
75 return zero<T>();
76 }
77 }
78 };
79
86 template<>
87 struct NumericLimits<Float<16>>
88 {
89 static constexpr Size digits()
90 {
91 return 7;
92 }
93
94 static constexpr Float<16> min()
95 {
96 return BFloat16::FromRepresentation(0x0080);
97 }
98
99 static constexpr Float<16> max()
100 {
101 return BFloat16::FromRepresentation(0x7F7F);
102 }
103
104 static constexpr Float<16> lowest()
105 {
106 return BFloat16::FromRepresentation(0xFF7F);
107 }
108
109 static constexpr Float<16> epsilon()
110 {
111 return BFloat16::FromRepresentation(0x3C00);
112 }
113
114 static constexpr Float<16> tolerance()
115 {
116 return BFloat16::FromRepresentation(0x3C24);
117 }
118 };
119}
120#endif // pRC_CORE_VALUE_LIMITS_H
static constexpr auto FromRepresentation(Representation const rep)
Definition bfloat16.hpp:34
Top-level class storing a floating point number.
Definition float.hpp:35
Definition cholesky.hpp:18
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
std::size_t Size
Definition type_traits.hpp:20
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
Any< IsFloat< T >, IsInteger< T > > IsValue
Definition type_traits.hpp:72
Definition type_traits.hpp:16
static constexpr Float< 16 > epsilon()
Definition limits.hpp:109
static constexpr Float< 16 > lowest()
Definition limits.hpp:104
static constexpr Size digits()
Definition limits.hpp:89
static constexpr Float< 16 > tolerance()
Definition limits.hpp:114
static constexpr Float< 16 > max()
Definition limits.hpp:99
static constexpr Float< 16 > min()
Definition limits.hpp:94
static constexpr T max()
Definition limits.hpp:39
static constexpr T min()
Definition limits.hpp:34
static constexpr Size digits()
Definition limits.hpp:29
static constexpr T epsilon()
Definition limits.hpp:49
static constexpr T lowest()
Definition limits.hpp:44
static constexpr T tolerance()
returns the relative accuracy of a pRC value type
Definition limits.hpp:60
Definition limits.hpp:13