cMHN 1.2
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
13#include <prc/core/log/log.hpp>
16
17namespace pRC
18{
19 template<Size W>
20 class Float
21 {
22 public:
24 Conditional<W == 32, float,
26
27 static constexpr Size Width = W;
28 template<Size C>
30
31 public:
33 requires IsDefined<Fundamental>
34 = default;
35 constexpr Float(Float const &) = default;
36 constexpr Float(Float &&) = default;
37 constexpr Float &operator=(Float const &) & = default;
38 constexpr Float &operator=(Float &&) & = default;
39 constexpr Float() = default;
40
41 template<class U>
42 requires IsConstructible<Fundamental, U>
43 constexpr Float(U const basic)
44 : mValue(basic)
45 {
46 }
47
48 template<IsValue U>
49 constexpr Float(U const &value)
50 : mValue(value())
51 {
52 }
53
54 constexpr Float(Zero<> const)
55 : Float(zero<Float>())
56 {
57 }
58
59 constexpr Float(Unit<> const)
60 : Float(unit<Float>())
61 {
62 }
63
64 constexpr Float(Identity<> const)
65 : Float(identity<Float>())
66 {
67 }
68
69 template<class U>
71 constexpr auto &operator=(U const basic) &
72 {
73 mValue = basic;
74 return *this;
75 }
76
77 template<IsValue U>
78 constexpr auto &operator=(U const &value) &
79 {
80 mValue = value();
81 return *this;
82 }
83
84 constexpr auto &operator=(Zero<> const) &
85 {
86 return *this = zero<Float>();
87 }
88
89 constexpr auto &operator=(Unit<> const) &
90 {
91 return *this = unit<Float>();
92 }
93
94 constexpr auto &operator=(Identity<> const) &
95 {
96 return *this = identity<Float>();
97 }
98
99 constexpr decltype(auto) operator()() &&
100 {
101 return move(mValue);
102 }
103
104 constexpr decltype(auto) operator()() const &&
105 {
106 return move(mValue);
107 }
108
109 constexpr auto &operator()() &
110 {
111 return mValue;
112 }
113
114 constexpr auto &operator()() const &
115 {
116 return mValue;
117 }
118
119 explicit constexpr operator Fundamental() const
120 {
121 return mValue;
122 }
123
124 template<class X>
126 constexpr auto &operator+=(X &&rhs) &
127 {
128 return *this = *this + forward<X>(rhs);
129 }
130
131 template<class X>
133 constexpr auto &operator-=(X &&rhs) &
134 {
135 return *this = *this - forward<X>(rhs);
136 }
137
138 template<class X>
140 constexpr auto &operator*=(X &&rhs) &
141 {
142 return *this = *this * forward<X>(rhs);
143 }
144
145 template<class X>
147 constexpr auto &operator/=(X &&rhs) &
148 {
149 return *this = *this / forward<X>(rhs);
150 }
151
152 private:
153 Fundamental mValue;
154 };
155
159}
160#endif // pRC_CORE_VALUE_FLOAT_H
Definition bfloat16.hpp:18
Definition value.hpp:12
static constexpr Size Width
Definition float.hpp:27
constexpr auto & operator=(Unit<> const) &
Definition float.hpp:89
constexpr auto & operator-=(X &&rhs) &
Definition float.hpp:133
constexpr Float(Unit<> const)
Definition float.hpp:59
constexpr auto & operator()() const &
Definition float.hpp:114
constexpr auto & operator=(U const &value) &
Definition float.hpp:78
constexpr auto & operator*=(X &&rhs) &
Definition float.hpp:140
constexpr Float(Identity<> const)
Definition float.hpp:64
constexpr auto & operator=(U const basic) &
Definition float.hpp:71
constexpr auto & operator=(Identity<> const) &
Definition float.hpp:94
constexpr Float(Zero<> const)
Definition float.hpp:54
constexpr auto & operator()() &
Definition float.hpp:109
constexpr auto & operator=(Zero<> const) &
Definition float.hpp:84
constexpr Float(U const &value)
Definition float.hpp:49
Conditional< W==16, BFloat16, Conditional< W==32, float, Conditional< W==64, double, Undefined > > > Fundamental
Definition float.hpp:23
constexpr auto & operator+=(X &&rhs) &
Definition float.hpp:126
~Float()=default
constexpr auto & operator/=(X &&rhs) &
Definition float.hpp:147
Definition concepts.hpp:40
Definition concepts.hpp:37
Definition concepts.hpp:16
Definition concepts.hpp:31
int value
Definition gmock-actions_test.cc:1714
Definition cholesky.hpp:10
static constexpr auto unit()
Definition unit.hpp:13
Float(Float< 16 >::Fundamental const) -> Float< 16 >
std::size_t Size
Definition basics.hpp:31
std::conditional_t< B, T, F > Conditional
Definition basics.hpp:56
static constexpr auto identity()
Definition identity.hpp:13
static constexpr auto zero()
Definition zero.hpp:12
Definition identity.hpp:11
Definition unit.hpp:11
Definition zero.hpp:11