pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
float.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_FLOAT_H
4#define pRC_CORE_VALUE_FLOAT_H
5
14#include <prc/core/log/log.hpp>
17
18namespace pRC
19{
33 template<Size W>
34 class Float
35 {
36 public:
39 Conditional<IsSatisfied<(W == 64)>, double, Undefined>>>;
40
41 static_assert(IsDefined<Fundamental>(),
42 "Float<W>: W has to be a supported Width (16, 32, 64).");
43
44 using Value = Float<W>;
45 template<class V, If<IsValue<V>> = 0>
46 using ChangeValue = V;
47
48 using Signed = True<>;
49 template<Bool R>
51
53 template<Size Q>
55
59
60 public:
61 ~Float() = default;
62 constexpr Float(Float const &) = default;
63 constexpr Float(Float &&) = default;
64 constexpr Float &operator=(Float const &) & = default;
65 constexpr Float &operator=(Float &&) & = default;
66 constexpr Float() = default;
67
79 template<class U, If<IsConstructible<Fundamental, U>> = 0>
80 constexpr Float(U const basic)
81 : mValue(basic)
82 {
83 }
84
93 template<class U, If<IsValue<U>> = 0>
94 constexpr Float(U const &value)
95 : mValue(value())
96 {
97 }
98
108 template<class U, If<IsValue<U>> = 0>
109 constexpr Float(Complex<U> const &value)
110 : Float(value.real())
111 {
112 }
113
119 constexpr Float(Zero<> const)
120 : Float(zero<Float>())
121 {
122 }
123
129 constexpr Float(Unit<> const)
130 : Float(unit<Float>())
131 {
132 }
133
139 constexpr Float(Identity<> const)
140 : Float(identity<Float>())
141 {
142 }
143
154 template<class U, If<IsAssignable<Fundamental, U>> = 0>
155 constexpr auto &operator=(U const basic) &
156 {
157 mValue = basic;
158 return *this;
159 }
160
169 template<class U, If<IsValue<U>> = 0>
170 constexpr auto &operator=(U const &value) &
171 {
172 mValue = value();
173 return *this;
174 }
175
185 template<class U, If<IsValue<U>> = 0>
186 constexpr auto &operator=(Complex<U> const &value) &
187 {
188 return *this = value.real();
189 }
190
196 constexpr auto &operator=(Zero<> const) &
197 {
198 return *this = zero<Float>();
199 }
200
206 constexpr auto &operator=(Unit<> const) &
207 {
208 return *this = unit<Float>();
209 }
210
216 constexpr auto &operator=(Identity<> const) &
217 {
218 return *this = identity<Float>();
219 }
220
221 constexpr decltype(auto) operator()() &&
222 {
223 return move(mValue);
224 }
225
226 constexpr decltype(auto) operator()() const &&
227 {
228 return move(mValue);
229 }
230
231 constexpr auto &operator()() &
232 {
233 return mValue;
234 }
235
236 constexpr auto &operator()() const &
237 {
238 return mValue;
239 }
240
241 explicit constexpr operator Fundamental() const
242 {
243 return mValue;
244 }
245
253 template<class X, If<IsInvocable<Add, Float &, X>> = 0>
254 constexpr auto &operator+=(X &&rhs) &
255 {
256 return *this = *this + forward<X>(rhs);
257 }
258
266 template<class X, If<IsInvocable<Sub, Float &, X>> = 0>
267 constexpr auto &operator-=(X &&rhs) &
268 {
269 return *this = *this - forward<X>(rhs);
270 }
271
279 template<class X, If<IsInvocable<Mul, Float &, X>> = 0>
280 constexpr auto &operator*=(X &&rhs) &
281 {
282 return *this = *this * forward<X>(rhs);
283 }
284
292 template<class X, If<IsInvocable<Div, Float &, X>> = 0>
293 constexpr auto &operator/=(X &&rhs) &
294 {
295 return *this = *this / forward<X>(rhs);
296 }
297
298 private:
299 Fundamental mValue;
300 };
301
305}
306#endif // pRC_CORE_VALUE_FLOAT_H
Custom Type representing a half-precision floating point number.
Definition bfloat16.hpp:26
Definition complex.hpp:26
Top-level class storing a floating point number.
Definition float.hpp:35
constexpr Float(Complex< U > const &value)
Float initializer from pRC::Complex object.
Definition float.hpp:109
constexpr auto & operator-=(X &&rhs) &
-= operator for Float
Definition float.hpp:267
constexpr Float & operator=(Float const &) &=default
constexpr Float(U const &value)
Float initializer from pRC value data type (like Float, Integer)
Definition float.hpp:94
pRC::Constant< Size, W > Width
Definition float.hpp:52
constexpr Float(Float &&)=default
Conditional< IsSatisfied<(W==16)>, BFloat16, Conditional< IsSatisfied<(W==32)>, float, Conditional< IsSatisfied<(W==64)>, double, Undefined > > > Fundamental
Definition float.hpp:39
constexpr auto & operator/=(X &&rhs) &
/= operator for Float
Definition float.hpp:293
constexpr auto & operator()() &
Definition float.hpp:231
constexpr auto & operator=(Zero<> const) &
Float assignment from pRC::Zero.
Definition float.hpp:196
constexpr auto & operator=(Identity<> const) &
Float assignment from pRC::Identity.
Definition float.hpp:216
~Float()=default
constexpr auto & operator=(Complex< U > const &value) &
Float assignment from Complex object.
Definition float.hpp:186
Conditional< IsSatisfied<(R)>, Float< W >, Undefined > ChangeSigned
Definition float.hpp:50
constexpr Float(U const basic)
Float initializer from standard data types (like float, double)
Definition float.hpp:80
constexpr auto & operator*=(X &&rhs) &
*= operator for Float
Definition float.hpp:280
constexpr Float(Float const &)=default
constexpr Float & operator=(Float &&) &=default
V ChangeValue
Definition float.hpp:46
constexpr auto & operator+=(X &&rhs) &
+= operator for Float
Definition float.hpp:254
constexpr Float(Zero<> const)
Float initializer from pRC::Zero.
Definition float.hpp:119
constexpr auto & operator=(U const &value) &
Float assignment from pRC value data type (like Float, Integer)
Definition float.hpp:170
constexpr auto & operator=(Unit<> const) &
Float assignment from pRC::Unit.
Definition float.hpp:206
constexpr Float(Unit<> const)
Float initializer from pRC::Unit.
Definition float.hpp:129
constexpr auto & operator=(U const basic) &
Float assignment from standard data types (like float, double)
Definition float.hpp:155
constexpr Float()=default
constexpr Float(Identity<> const)
Float initializer from pRC::Identity.
Definition float.hpp:139
constexpr auto & operator()() const &
Definition float.hpp:236
Definition cholesky.hpp:18
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto zero()
Definition zero.hpp:12
std::integral_constant< T, V > Constant
Definition type_traits.hpp:34
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto unit()
Definition unit.hpp:12
std::conditional_t< B{}, T, F > Conditional
Definition type_traits.hpp:131
static constexpr auto identity()
Definition identity.hpp:12
Definition type_traits.hpp:262
Definition type_traits.hpp:265
Definition type_traits.hpp:268