mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 15:10:19 +00:00
AK: Add 16-bit float type
This commit is contained in:
parent
653c8f231d
commit
c1ec2ddb63
Notes:
github-actions[bot]
2024-11-10 21:49:27 +00:00
Author: https://github.com/rmg-x Commit: https://github.com/LadybirdBrowser/ladybird/commit/c1ec2ddb639 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2184 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/trflynn89
5 changed files with 34 additions and 0 deletions
|
@ -1012,6 +1012,13 @@ ErrorOr<void> Formatter<long double>::format(FormatBuilder& builder, long double
|
||||||
return builder.put_f80(value, base, upper_case, m_use_separator, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode);
|
return builder.put_f80(value, base, upper_case, m_use_separator, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> Formatter<f16>::format(FormatBuilder& builder, f16 value)
|
||||||
|
{
|
||||||
|
// FIXME: Create a proper put_f16() implementation
|
||||||
|
Formatter<double> formatter { *this };
|
||||||
|
return TRY(formatter.format(builder, static_cast<double>(value)));
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<void> Formatter<double>::format(FormatBuilder& builder, double value)
|
ErrorOr<void> Formatter<double>::format(FormatBuilder& builder, double value)
|
||||||
{
|
{
|
||||||
u8 base;
|
u8 base;
|
||||||
|
|
11
AK/Format.h
11
AK/Format.h
|
@ -551,6 +551,17 @@ struct Formatter<long double> : StandardFormatter {
|
||||||
ErrorOr<void> format(FormatBuilder&, long double value);
|
ErrorOr<void> format(FormatBuilder&, long double value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Formatter<f16> : StandardFormatter {
|
||||||
|
Formatter() = default;
|
||||||
|
explicit Formatter(StandardFormatter formatter)
|
||||||
|
: StandardFormatter(formatter)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> format(FormatBuilder&, f16 value);
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<nullptr_t> : Formatter<FlatPtr> {
|
struct Formatter<nullptr_t> : Formatter<FlatPtr> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, nullptr_t)
|
ErrorOr<void> format(FormatBuilder& builder, nullptr_t)
|
||||||
|
|
|
@ -143,6 +143,17 @@ struct NumericLimits<long double> {
|
||||||
static constexpr size_t digits() { return __LDBL_MANT_DIG__; }
|
static constexpr size_t digits() { return __LDBL_MANT_DIG__; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct NumericLimits<f16> {
|
||||||
|
static constexpr f16 lowest() { return -__FLT16_MAX__; }
|
||||||
|
static constexpr f16 min_normal() { return __FLT16_MIN__; }
|
||||||
|
static constexpr f16 min_denormal() { return __FLT16_DENORM_MIN__; }
|
||||||
|
static constexpr f16 max() { return __FLT16_MAX__; }
|
||||||
|
static constexpr f16 epsilon() { return __FLT16_EPSILON__; }
|
||||||
|
static constexpr bool is_signed() { return true; }
|
||||||
|
static constexpr size_t digits() { return __FLT16_MANT_DIG__; }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
#if USING_AK_GLOBALLY
|
||||||
|
|
|
@ -350,6 +350,8 @@ template<>
|
||||||
inline constexpr bool __IsFloatingPoint<double> = true;
|
inline constexpr bool __IsFloatingPoint<double> = true;
|
||||||
template<>
|
template<>
|
||||||
inline constexpr bool __IsFloatingPoint<long double> = true;
|
inline constexpr bool __IsFloatingPoint<long double> = true;
|
||||||
|
template<>
|
||||||
|
inline constexpr bool __IsFloatingPoint<f16> = true;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline constexpr bool IsFloatingPoint = __IsFloatingPoint<RemoveCV<T>>;
|
inline constexpr bool IsFloatingPoint = __IsFloatingPoint<RemoveCV<T>>;
|
||||||
|
|
|
@ -17,6 +17,9 @@ using i32 = __INT32_TYPE__;
|
||||||
using i16 = __INT16_TYPE__;
|
using i16 = __INT16_TYPE__;
|
||||||
using i8 = __INT8_TYPE__;
|
using i8 = __INT8_TYPE__;
|
||||||
|
|
||||||
|
using f16 = _Float16;
|
||||||
|
static_assert(__FLT16_MANT_DIG__ == 11 && __FLT16_MAX_EXP__ == 16);
|
||||||
|
|
||||||
using f32 = float;
|
using f32 = float;
|
||||||
static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128);
|
static_assert(__FLT_MANT_DIG__ == 24 && __FLT_MAX_EXP__ == 128);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue