11namespace hi::inline v1 {
13constexpr uint32_t float16_bias = 15;
14constexpr uint32_t float32_bias = 127;
15constexpr uint32_t f32_to_f16_adjustment_exponent = float32_bias - float16_bias;
16constexpr uint32_t f32_to_f16_lowest_normal_exponent = 0x01 + f32_to_f16_adjustment_exponent;
17constexpr uint32_t f32_to_f16_infinite_exponent = 0x1f + f32_to_f16_adjustment_exponent;
18constexpr uint32_t f32_to_f16_adjustment = f32_to_f16_adjustment_exponent << 23;
19constexpr uint32_t f32_to_f16_lowest_normal = f32_to_f16_lowest_normal_exponent << 23;
20constexpr uint32_t f32_to_f16_infinite = f32_to_f16_infinite_exponent << 23;
22constexpr float cvtsh_ss(uint16_t value)
noexcept
28 hilet sign = (u >> 15) << 31;
34 u = u + f32_to_f16_adjustment;
37 hilet is_normal = u > (f32_to_f16_lowest_normal - 1);
43 u = is_normal ? u : 0;
45 return std::bit_cast<float>(u);
48constexpr uint16_t cvtss_sh(
float value)
noexcept
51 auto u = std::bit_cast<uint32_t>(value);
54 hilet sign =
static_cast<uint32_t
>(
static_cast<int32_t
>(u) >> 31) << 15;
60 hilet is_normal = u > (f32_to_f16_lowest_normal - 1);
63 u =
std::min(u, f32_to_f16_infinite);
66 u = u - f32_to_f16_adjustment;
72 u = is_normal ? u : 0;
79 return static_cast<uint16_t
>(u);
86 constexpr float16() noexcept : v(0) {}
92 constexpr explicit float16(
float other) noexcept : v(cvtss_sh(other)) {}
93 constexpr explicit float16(
double other) noexcept :
float16(
static_cast<float>(other)) {}
94 constexpr explicit float16(
long double other) noexcept :
float16(
static_cast<float>(other)) {}
96 constexpr float16 &operator=(
float other)
noexcept
102 constexpr operator float()
const noexcept
107 [[nodiscard]]
static constexpr float16 from_uint16_t(uint16_t
const rhs)
noexcept
114 [[nodiscard]]
constexpr uint16_t get()
const noexcept
119 constexpr float16 &set(uint16_t rhs)
noexcept
130 [[nodiscard]]
constexpr friend bool operator==(
float16 const &lhs,
float16 const &rhs)
noexcept =
default;
134 return float16{
static_cast<float>(lhs) *
static_cast<float>(rhs)};
151 using value_type = hi::float16;
153 static constexpr bool is_specialized =
true;
155 static constexpr bool is_integer =
false;
156 static constexpr bool is_exact =
false;
157 static constexpr bool has_infinity =
true;
158 static constexpr bool has_quiet_NaN =
true;
159 static constexpr bool has_signaling_NaN =
false;
160 static constexpr float_denorm_style has_denorm = std::denorm_present;
161 static constexpr bool has_denorm_loss =
false;
162 static constexpr float_round_style round_style = std::round_to_nearest;
163 static constexpr bool is_iec559 =
true;
164 static constexpr bool is_bounded =
true;
165 static constexpr bool is_modulo =
false;
166 static constexpr int digits = 10;
167 static constexpr int digits10 = 4;
168 static constexpr int max_digits10 = 4;
169 static constexpr int min_exponent = -14;
170 static constexpr int min_exponent10 = -3;
171 static constexpr int max_exponent = 15;
172 static constexpr int max_exponent10 = 3;
173 static constexpr bool traps =
false;
174 static constexpr bool tinyness_before =
false;
176 static constexpr value_type
min()
noexcept
178 return hi::float16::from_uint16_t(0x0400);
181 static constexpr value_type
lowest()
noexcept
183 return hi::float16::from_uint16_t(0xfbff);
186 static constexpr value_type
max()
noexcept
188 return hi::float16::from_uint16_t(0x7bff);
191 static constexpr value_type
epsilon()
noexcept
193 return hi::float16::from_uint16_t(0xfbff);
198 return hi::float16::from_uint16_t(0x3800);
201 static constexpr value_type
infinity()
noexcept
203 return hi::float16::from_uint16_t(0x7c00);
206 static constexpr value_type
quiet_NaN()
noexcept
208 return hi::float16::from_uint16_t(0x7c01);
213 return hi::float16::from_uint16_t(0x7e01);
216 static constexpr value_type
denorm_min()
noexcept
218 return hi::float16::from_uint16_t(0x0001);
This file includes required definitions.
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
Definition float16.hpp:82
T signaling_NaN(T... args)