30 constexpr half()
noexcept =
default;
31 constexpr half(
half const&)
noexcept =
default;
32 constexpr half(
half&&)
noexcept =
default;
33 constexpr half& operator=(
half const&)
noexcept =
default;
34 constexpr half& operator=(
half&&)
noexcept =
default;
35 constexpr half(std::in_place_t, uint16_t v) noexcept : v(v) {}
37 constexpr explicit half(
float other) noexcept : v(float_to_half(
other)) {}
39 constexpr operator float()
const noexcept
41 return half_to_float(v);
44 [[nodiscard]]
constexpr uint16_t
const& intrinsic()
const noexcept
49 [[nodiscard]]
constexpr uint16_t& intrinsic()
noexcept
54 constexpr half& operator=(
float other)
noexcept
56 v = float_to_half(
other);
65 template<
typename LHS,
typename RHS>
66 [[nodiscard]]
constexpr friend bool operator==(LHS lhs, RHS rhs)
noexcept requires requires {
67 static_cast<float>(lhs);
68 static_cast<float>(rhs);
71 return static_cast<float>(lhs) ==
static_cast<float>(rhs);
74 template<
typename LHS,
typename RHS>
75 [[nodiscard]]
constexpr friend auto operator<=>(LHS lhs, RHS rhs)
noexcept requires requires {
76 static_cast<float>(lhs);
77 static_cast<float>(rhs);
80 return static_cast<float>(lhs) <=>
static_cast<float>(rhs);
83#define HI_X_binary_math_op(op) \
84 template<typename LHS, typename RHS> \
85 [[nodiscard]] constexpr friend float operator op(LHS lhs, RHS rhs) noexcept requires requires { \
86 static_cast<float>(lhs); \
87 static_cast<float>(rhs); \
90 return half{static_cast<float>(lhs) op static_cast<float>(rhs)}; \
94 HI_X_binary_math_op(+)
95 HI_X_binary_math_op(-)
96 HI_X_binary_math_op(*)
97 HI_X_binary_math_op(/)
99#undef HI_X_binary_math_op
109#define HI_X_binary_bit_op(op) \
110 [[nodiscard]] constexpr friend half operator op(half const& lhs, half const& rhs) noexcept \
112 return half(std::in_place, lhs.v op rhs.v); \
116 HI_X_binary_bit_op(|)
117 HI_X_binary_bit_op(&)
118 HI_X_binary_bit_op(^)
120#undef HI_X_binary_bit_op
159 constexpr static bool is_specialized =
true;
161 constexpr static bool is_integer =
false;
162 constexpr static bool is_exact =
false;
163 constexpr static bool has_infinity =
true;
164 constexpr static bool has_quiet_NaN =
true;
165 constexpr static bool has_signaling_NaN =
false;
166 constexpr static float_round_style round_style = round_to_nearest;
167 constexpr static bool is_iec559 =
true;
168 constexpr static bool is_bounded =
true;
169 constexpr static bool is_modulo =
false;
170 constexpr static int digits = 10;
171 constexpr static int digits10 = 4;
172 constexpr static int max_digits10 = 4;
173 constexpr static int min_exponent = -14;
174 constexpr static int min_exponent10 = -3;
175 constexpr static int max_exponent = 15;
176 constexpr static int max_exponent10 = 3;
177 constexpr static bool traps =
false;
178 constexpr static bool tinyness_before =
false;
182 return ::hi::half(std::in_place, 0x0400);
187 return ::hi::half(std::in_place, 0xfbff);
192 return ::hi::half(std::in_place, 0x7bff);
197 return ::hi::half(std::in_place, 0xfbff);
202 return ::hi::half(std::in_place, 0x3800);
207 return ::hi::half(std::in_place, 0x7c00);
212 return ::hi::half(std::in_place, 0x7c01);
217 return ::hi::half(std::in_place, 0x7e01);
222 return ::hi::half(std::in_place, 0x0001);