8#include "half_to_float.hpp"
9#include "float_to_half.hpp"
17hi_export_module(hikocpu : half);
22hi_warning_ignore_msvc(26472);
24hi_export
namespace hi {
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
124static_assert(
sizeof(
half) ==
sizeof(uint16_t));
125static_assert(std::is_trivially_copy_constructible_v<half>);
126static_assert(std::is_trivially_move_constructible_v<half>);
127static_assert(std::is_trivially_copy_assignable_v<half>);
128static_assert(std::is_trivially_move_assignable_v<half>);
129static_assert(std::is_trivially_destructible_v<half>);
131static_assert(
requires(
half a) { std::bit_cast<uint16_t>(a); });
132static_assert(
requires(uint16_t a) { std::bit_cast<half>(a); });
137hi_export
namespace std {
148struct formatter<::
hi::half, char> : formatter<float, char> {
149 constexpr auto format(
::hi::half const& t,
auto& fc)
const
151 return formatter<float, char>::format(
static_cast<float>(t), fc);
159 constexpr static bool is_specialized =
true;
160 constexpr static bool is_signed =
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;
180 constexpr static value_type
min()
noexcept
182 return ::hi::half(std::in_place, 0x0400);
185 constexpr static value_type
lowest()
noexcept
187 return ::hi::half(std::in_place, 0xfbff);
190 constexpr static value_type
max()
noexcept
192 return ::hi::half(std::in_place, 0x7bff);
195 constexpr static value_type
epsilon()
noexcept
197 return ::hi::half(std::in_place, 0xfbff);
202 return ::hi::half(std::in_place, 0x3800);
205 constexpr static value_type
infinity()
noexcept
207 return ::hi::half(std::in_place, 0x7c00);
210 constexpr static value_type
quiet_NaN()
noexcept
212 return ::hi::half(std::in_place, 0x7c01);
217 return ::hi::half(std::in_place, 0x7e01);
220 constexpr static value_type
denorm_min()
noexcept
222 return ::hi::half(std::in_place, 0x0001);
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:24
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
T signaling_NaN(T... args)