cMHN 1.1
C++ library for learning MHNs with pRC
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{
20 template<Size W>
21 class Float
22 {
23 public:
26 Conditional<IsSatisfied<(W == 64)>, double, Undefined>>>;
27
28 static_assert(IsDefined<Fundamental>(),
29 "Float<W>: W has to be a supported Width (16, 32, 64).");
30
31 using Value = Float<W>;
32 template<class V, If<IsValue<V>> = 0>
33 using ChangeValue = V;
34
35 using Signed = True<>;
36 template<Bool R>
38
40 template<Size Q>
42
46
47 public:
48 ~Float() = default;
49 constexpr Float(Float const &) = default;
50 constexpr Float(Float &&) = default;
51 constexpr Float &operator=(Float const &) & = default;
52 constexpr Float &operator=(Float &&) & = default;
53 constexpr Float() = default;
54
55 template<class U, If<IsConstructible<Fundamental, U>> = 0>
56 constexpr Float(U const basic)
57 : mValue(basic)
58 {
59 }
60
61 template<class U, If<IsValue<U>> = 0>
62 constexpr Float(U const &value)
63 : mValue(value())
64 {
65 }
66
67 template<class U, If<IsValue<U>> = 0>
68 constexpr Float(Complex<U> const &value)
69 : Float(value.real())
70 {
71 }
72
73 constexpr Float(Zero<> const)
74 : Float(zero<Float>())
75 {
76 }
77
78 constexpr Float(Unit<> const)
79 : Float(unit<Float>())
80 {
81 }
82
83 constexpr Float(Identity<> const)
84 : Float(identity<Float>())
85 {
86 }
87
88 template<class U, If<IsAssignable<Fundamental, U>> = 0>
89 constexpr auto &operator=(U const basic) &
90 {
91 mValue = basic;
92 return *this;
93 }
94
95 template<class U, If<IsValue<U>> = 0>
96 constexpr auto &operator=(U const &value) &
97 {
98 mValue = value();
99 return *this;
100 }
101
102 template<class U, If<IsValue<U>> = 0>
103 constexpr auto &operator=(Complex<U> const &value) &
104 {
105 return *this = value.real();
106 }
107
108 constexpr auto &operator=(Zero<> const) &
109 {
110 return *this = zero<Float>();
111 }
112
113 constexpr auto &operator=(Unit<> const) &
114 {
115 return *this = unit<Float>();
116 }
117
118 constexpr auto &operator=(Identity<> const) &
119 {
120 return *this = identity<Float>();
121 }
122
123 constexpr decltype(auto) operator()() &&
124 {
125 return move(mValue);
126 }
127
128 constexpr decltype(auto) operator()() const &&
129 {
130 return move(mValue);
131 }
132
133 constexpr auto &operator()() &
134 {
135 return mValue;
136 }
137
138 constexpr auto &operator()() const &
139 {
140 return mValue;
141 }
142
143 explicit constexpr operator Fundamental() const
144 {
145 return mValue;
146 }
147
148 template<class X, If<IsInvocable<Add, Float &, X>> = 0>
149 constexpr auto &operator+=(X &&rhs) &
150 {
151 return *this = *this + forward<X>(rhs);
152 }
153
154 template<class X, If<IsInvocable<Sub, Float &, X>> = 0>
155 constexpr auto &operator-=(X &&rhs) &
156 {
157 return *this = *this - forward<X>(rhs);
158 }
159
160 template<class X, If<IsInvocable<Mul, Float &, X>> = 0>
161 constexpr auto &operator*=(X &&rhs) &
162 {
163 return *this = *this * forward<X>(rhs);
164 }
165
166 template<class X, If<IsInvocable<Div, Float &, X>> = 0>
167 constexpr auto &operator/=(X &&rhs) &
168 {
169 return *this = *this / forward<X>(rhs);
170 }
171
172 private:
173 Fundamental mValue;
174 };
175
179}
180#endif // pRC_CORE_VALUE_FLOAT_H
Definition bfloat16.hpp:18
Definition complex.hpp:26
Definition float.hpp:22
constexpr Float(Complex< U > const &value)
Definition float.hpp:68
constexpr auto & operator-=(X &&rhs) &
Definition float.hpp:155
constexpr Float & operator=(Float const &) &=default
constexpr Float(U const &value)
Definition float.hpp:62
pRC::Constant< Size, W > Width
Definition float.hpp:39
constexpr Float(Float &&)=default
constexpr auto & operator/=(X &&rhs) &
Definition float.hpp:167
constexpr auto & operator()() &
Definition float.hpp:133
constexpr auto & operator=(Zero<> const) &
Definition float.hpp:108
constexpr auto & operator=(Identity<> const) &
Definition float.hpp:118
Conditional< IsSatisfied<(W==16)>, BFloat16, Conditional< IsSatisfied<(W==32)>, float, Conditional< IsSatisfied<(W==64)>, double, Undefined > > > Fundamental
Definition float.hpp:24
~Float()=default
constexpr auto & operator=(Complex< U > const &value) &
Definition float.hpp:103
Conditional< IsSatisfied<(R)>, Float< W >, Undefined > ChangeSigned
Definition float.hpp:37
constexpr Float(U const basic)
Definition float.hpp:56
constexpr auto & operator*=(X &&rhs) &
Definition float.hpp:161
constexpr Float(Float const &)=default
constexpr Float & operator=(Float &&) &=default
V ChangeValue
Definition float.hpp:33
constexpr auto & operator+=(X &&rhs) &
Definition float.hpp:149
constexpr Float(Zero<> const)
Definition float.hpp:73
constexpr auto & operator=(U const &value) &
Definition float.hpp:96
constexpr auto & operator=(Unit<> const) &
Definition float.hpp:113
constexpr Float(Unit<> const)
Definition float.hpp:78
constexpr auto & operator=(U const basic) &
Definition float.hpp:89
constexpr Float()=default
constexpr Float(Identity<> const)
Definition float.hpp:83
constexpr auto & operator()() const &
Definition float.hpp:138
Definition cholesky.hpp:18
Float(Float< 16 >::Fundamental const) -> Float< 16 >
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr decltype(auto) real(X &&a)
Definition real.hpp:11
static constexpr auto zero()
Definition zero.hpp:12
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr auto unit()
Definition unit.hpp:12
std::integral_constant< T, V > Constant
Definition type_traits.hpp:34
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