7#include "../macros.hpp"
8#include "half_to_float.hpp"
9#include "float_to_half.hpp"
17hi_export_module(hikogui.utility.half);
22hi_warning_ignore_msvc(26472);
24hi_export
namespace hi {
inline namespace v1 {
29 constexpr half()
noexcept =
default;
30 constexpr half(
half const&)
noexcept =
default;
31 constexpr half(
half&&)
noexcept =
default;
32 constexpr half& operator=(
half const&)
noexcept =
default;
33 constexpr half& operator=(
half&&)
noexcept =
default;
39 constexpr half(std::in_place_t, uint16_t v)
noexcept : v(v) {}
41 [[
nodiscard]]
constexpr uint16_t
const& intrinsic()
const noexcept
46 [[
nodiscard]]
constexpr uint16_t& intrinsic()
noexcept
51 constexpr half& operator=(
float other)
noexcept
53 v = float_to_half(
other);
57 constexpr operator float()
const noexcept
59 return half_to_float(v);
67 [[
nodiscard]]
constexpr friend bool operator==(
half const& lhs,
half const& rhs)
noexcept
69 return static_cast<float>(lhs) ==
static_cast<float>(rhs);
72 [[
nodiscard]]
constexpr friend auto operator<=>(
half const& lhs,
half const& rhs)
noexcept
74 return static_cast<float>(lhs) <=>
static_cast<float>(rhs);
77#define HI_X_binary_math_op(op) \
78 [[nodiscard]] constexpr friend half operator op(half const& lhs, half const& rhs) noexcept \
80 return half{static_cast<float>(lhs) op static_cast<float>(rhs)}; \
84 HI_X_binary_math_op(+)
85 HI_X_binary_math_op(-)
86 HI_X_binary_math_op(*)
87 HI_X_binary_math_op(/)
89#undef HI_X_binary_math_op
99#define HI_X_binary_bit_op(op) \
100 [[nodiscard]] constexpr friend half operator op(half const& lhs, half const& rhs) noexcept \
102 return half(std::in_place, lhs.v op rhs.v); \
106 HI_X_binary_bit_op(|)
107 HI_X_binary_bit_op(&)
108 HI_X_binary_bit_op(^)
110#undef HI_X_binary_bit_op
114static_assert(
sizeof(
half) ==
sizeof(uint16_t));
115static_assert(std::is_trivially_copy_constructible_v<half>);
116static_assert(std::is_trivially_move_constructible_v<half>);
117static_assert(std::is_trivially_copy_assignable_v<half>);
118static_assert(std::is_trivially_move_assignable_v<half>);
119static_assert(std::is_trivially_destructible_v<half>);
121static_assert(
requires(
half a) { std::bit_cast<uint16_t>(a); });
122static_assert(
requires(uint16_t a) { std::bit_cast<half>(a); });
126hi_export
namespace std {
138struct formatter<::
hi::half, char> : formatter<float, char> {
139 constexpr auto format(
::hi::half const& t,
auto& fc)
const
141 return formatter<float, char>::format(
static_cast<float>(t), fc);
149 constexpr static bool is_specialized =
true;
151 constexpr static bool is_integer =
false;
152 constexpr static bool is_exact =
false;
153 constexpr static bool has_infinity =
true;
154 constexpr static bool has_quiet_NaN =
true;
155 constexpr static bool has_signaling_NaN =
false;
156 constexpr static float_round_style round_style = round_to_nearest;
157 constexpr static bool is_iec559 =
true;
158 constexpr static bool is_bounded =
true;
159 constexpr static bool is_modulo =
false;
160 constexpr static int digits = 10;
161 constexpr static int digits10 = 4;
162 constexpr static int max_digits10 = 4;
163 constexpr static int min_exponent = -14;
164 constexpr static int min_exponent10 = -3;
165 constexpr static int max_exponent = 15;
166 constexpr static int max_exponent10 = 3;
167 constexpr static bool traps =
false;
168 constexpr static bool tinyness_before =
false;
172 return ::hi::half(std::in_place, 0x0400);
177 return ::hi::half(std::in_place, 0xfbff);
182 return ::hi::half(std::in_place, 0x7bff);
187 return ::hi::half(std::in_place, 0xfbff);
192 return ::hi::half(std::in_place, 0x3800);
197 return ::hi::half(std::in_place, 0x7c00);
202 return ::hi::half(std::in_place, 0x7c01);
207 return ::hi::half(std::in_place, 0x7e01);
212 return ::hi::half(std::in_place, 0x0001);
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
T signaling_NaN(T... args)