25 constexpr fp16() noexcept = default;
40 constexpr operator float (
this fp16 self)
noexcept {
return self.content; }
43 constexpr operator _Float16 (
this fp16 self)
noexcept {
return self.content; }
54 friend constexpr
bool operator == (
fp16 x,
fp16 y) noexcept {
60 return x.content != y.content;
65 return x.content <=> y.content;
70 return x.content < y.content;
75 return x.content <= y.content;
79 return x.content > y.content;
84 return x.content >= y.content;
88 friend constexpr void swap(
93 swap(x.content,y.content);
98 return std::bit_cast<fp16>(data);
103 return std::bit_cast<uint16_t>(self.content);
109constexpr fp16 operator""_fp16(
long double v)
noexcept {
110 return fp16(
static_cast<float>(v));
119 return (x.to_bits() & 0x7FFF) > 0x7c00;
125 static constexpr bool is_specialized =
true;
138 static constexpr int digits = 11;
139 static constexpr int digits10 = 3;
140 static constexpr bool is_signed =
true;
141 static constexpr bool is_integer =
false;
142 static constexpr bool is_exact =
false;
143 static constexpr int radix = 2;
152 static constexpr int min_exponent = -13;
153 static constexpr int min_exponent10 = -4;
154 static constexpr int max_exponent = 16;
155 static constexpr int max_exponent10 = 4;
156 static constexpr bool has_infinity =
true;
157 static constexpr bool has_quiet_NaN =
true;
158 static constexpr bool has_signaling_NaN =
true;
159 static constexpr float_denorm_style has_denorm = denorm_absent;
160 static constexpr bool has_denorm_loss =
false;
177 static constexpr bool is_iec559 =
false;
178 static constexpr bool is_bounded =
false;
179 static constexpr bool is_modulo =
false;
180 static constexpr bool traps =
false;
181 static constexpr bool tinyness_before =
false;
182 static constexpr float_round_style round_style = round_to_nearest;
185 extern template class numeric_limits<ein::fp16>;
189#if defined(EIN_TESTING) || defined(EIN_TESTING_FP16)
190TEST_CASE(
"fp16",
"[fp16]") {
194 SECTION(
"fp16 default constructors and conversion") {
195 CHECK(
fp16(0.5f).content == Approx(0.5f));
196 CHECK(0.25_fp16 .content == Approx(0.25f));
197 CHECK(
static_cast<float>(1.0_fp16) == Approx(1.0f));
198 CHECK(
static_cast<_Float16
>(0.75_fp16) == Approx(_Float16(0.75f)));
201 SECTION(
"fp16 comparison operators") {
202 CHECK(0.5_fp16 == 0.5_fp16);
203 CHECK(0.1_fp16 < 0.2_fp16);
204 CHECK(0.3_fp16 > 0.2_fp16);
205 CHECK(0.2_fp16 <= 0.2_fp16);
206 CHECK(0.2_fp16 >= 0.2_fp16);
209 SECTION(
"fp16 swap function") {
210 fp16 x(1.0_fp16), y(2.0_fp16);
212 CHECK(x ==
fp16(2.0_fp16));
213 CHECK(y ==
fp16(1.0_fp16));
216 SECTION(
"fp16 bit operations") {
217 fp16 val = fp16::from_bits(0x3C00);
218 CHECK(val.
to_bits() == 0x3C00);
219 CHECK(fp16::from_bits(0x7C00) == std::numeric_limits<fp16>::infinity());
222 SECTION(
"fp16 isnan function") {
227 SECTION(
"fp16 numeric_limits") {
228 using nl = std::numeric_limits<fp16>;
230 CHECK(nl::is_specialized);
231 CHECK(nl::is_signed);
232 CHECK(nl::digits == 11);
233 CHECK(nl::epsilon() == fp16::from_bits(0x1200));
234 CHECK(nl::round_error() == fp16::from_bits(0x3C00));
235 CHECK(nl::min() == fp16::from_bits(0x0200));
236 CHECK(nl::max() == fp16::from_bits(0x7BFF));
237 CHECK(nl::lowest() == fp16::from_bits(0xFBFF));
238 CHECK(nl::infinity() == fp16::from_bits(0x7C00));
241 CHECK(nl::denorm_min() == fp16::from_bits(0));
static constexpr ein::fp16 infinity() noexcept
static constexpr ein::fp16 quiet_NaN() noexcept
static constexpr ein::fp16 min() noexcept
static constexpr ein::fp16 lowest() noexcept
static constexpr ein::fp16 signaling_NaN() noexcept
static constexpr ein::fp16 round_error() noexcept
static constexpr ein::fp16 denorm_min() noexcept
static constexpr ein::fp16 epsilon() noexcept
static constexpr ein::fp16 max() noexcept
#define ein_reinitializes
[[clang::reinitializes]]
#define ein_artificial
[[artificial]].
#define ein_inline
inline [[always_inline]]
#define ein_lifetimebound
[[lifetimebound]]
#define ein_noescape
portable __attribute__((noescape))
#define ein_nodiscard
C++17 [[nodiscard]].
#define ein_const
[[const]] is not const
constexpr bool isnan(ein::bf16 x) noexcept
friend constexpr std::partial_ordering operator<=>(fp16 x, fp16 y) noexcept
friend constexpr bool operator<(fp16 x, fp16 y) noexcept
static constexpr fp16 from_bits(uint16_t data) noexcept
ein_reinitializes constexpr fp16 & operator=(fp16 const &) noexcept=default
friend constexpr bool operator<=(fp16 x, fp16 y) noexcept
friend constexpr bool operator>=(fp16 x, fp16 y) noexcept
friend constexpr bool operator!=(fp16 x, fp16 y) noexcept
friend constexpr bool operator>(fp16 x, fp16 y) noexcept
constexpr uint16_t to_bits(this fp16 self) noexcept
friend constexpr void swap(fp16 &x, fp16 &y) noexcept
constexpr fp16(_Float16 content) noexcept
constexpr fp16() noexcept=default