15hi_warning_ignore_msvc(26472);
17namespace hi::inline
v1 {
19constexpr uint32_t float16_bias = 15;
20constexpr uint32_t float32_bias = 127;
21constexpr uint32_t f32_to_f16_adjustment_exponent = float32_bias - float16_bias;
22constexpr uint32_t f32_to_f16_lowest_normal_exponent = 0x01 + f32_to_f16_adjustment_exponent;
23constexpr uint32_t f32_to_f16_infinite_exponent = 0x1f + f32_to_f16_adjustment_exponent;
24constexpr uint32_t f32_to_f16_adjustment = f32_to_f16_adjustment_exponent << 23;
25constexpr uint32_t f32_to_f16_lowest_normal = f32_to_f16_lowest_normal_exponent << 23;
26constexpr uint32_t f32_to_f16_infinite = f32_to_f16_infinite_exponent << 23;
28constexpr float cvtsh_ss(uint16_t value)
noexcept
34 hilet sign = (u >> 15) << 31;
40 u = u + f32_to_f16_adjustment;
43 hilet is_normal = u > (f32_to_f16_lowest_normal - 1);
49 u = is_normal ? u : 0;
51 return std::bit_cast<float>(u);
54constexpr uint16_t cvtss_sh(
float value)
noexcept
57 auto u = std::bit_cast<uint32_t>(value);
60 hilet sign =
static_cast<uint32_t
>(
static_cast<int32_t
>(u) >> 31) << 15;
66 hilet is_normal = u > (f32_to_f16_lowest_normal - 1);
69 u =
std::min(u, f32_to_f16_infinite);
72 u = u - f32_to_f16_adjustment;
78 u = is_normal ? u : 0;
85 return static_cast<uint16_t
>(u);
92 constexpr float16() noexcept : v(0) {}
98 constexpr explicit float16(
float other) noexcept : v(cvtss_sh(other)) {}
99 constexpr explicit float16(
double other) noexcept :
float16(
static_cast<float>(other)) {}
100 constexpr explicit float16(
long double other) noexcept :
float16(
static_cast<float>(other)) {}
102 constexpr float16 &operator=(
float other)
noexcept
108 constexpr operator float()
const noexcept
113 [[nodiscard]]
static constexpr float16 from_uint16_t(uint16_t
const rhs)
noexcept
120 [[nodiscard]]
constexpr uint16_t get()
const noexcept
125 constexpr float16 &set(uint16_t rhs)
noexcept
136 [[nodiscard]]
constexpr friend bool operator==(
float16 const &lhs,
float16 const &rhs)
noexcept =
default;
140 return float16{
static_cast<float>(lhs) *
static_cast<float>(rhs)};
157 using value_type = hi::float16;
159 static constexpr bool is_specialized =
true;
161 static constexpr bool is_integer =
false;
162 static constexpr bool is_exact =
false;
163 static constexpr bool has_infinity =
true;
164 static constexpr bool has_quiet_NaN =
true;
165 static constexpr bool has_signaling_NaN =
false;
166 static constexpr float_denorm_style has_denorm = std::denorm_present;
167 static constexpr bool has_denorm_loss =
false;
168 static constexpr float_round_style round_style = std::round_to_nearest;
169 static constexpr bool is_iec559 =
true;
170 static constexpr bool is_bounded =
true;
171 static constexpr bool is_modulo =
false;
172 static constexpr int digits = 10;
173 static constexpr int digits10 = 4;
174 static constexpr int max_digits10 = 4;
175 static constexpr int min_exponent = -14;
176 static constexpr int min_exponent10 = -3;
177 static constexpr int max_exponent = 15;
178 static constexpr int max_exponent10 = 3;
179 static constexpr bool traps =
false;
180 static constexpr bool tinyness_before =
false;
182 static constexpr value_type
min()
noexcept
184 return hi::float16::from_uint16_t(0x0400);
187 static constexpr value_type
lowest()
noexcept
189 return hi::float16::from_uint16_t(0xfbff);
192 static constexpr value_type
max()
noexcept
194 return hi::float16::from_uint16_t(0x7bff);
197 static constexpr value_type
epsilon()
noexcept
199 return hi::float16::from_uint16_t(0xfbff);
204 return hi::float16::from_uint16_t(0x3800);
207 static constexpr value_type
infinity()
noexcept
209 return hi::float16::from_uint16_t(0x7c00);
212 static constexpr value_type
quiet_NaN()
noexcept
214 return hi::float16::from_uint16_t(0x7c01);
219 return hi::float16::from_uint16_t(0x7e01);
222 static constexpr value_type
denorm_min()
noexcept
224 return hi::float16::from_uint16_t(0x0001);
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Definition float16.hpp:88
T signaling_NaN(T... args)