mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
AK: Fix printing of negative FixedPoint values
Fixes #17514 by comparing to 0 before truncating the fractional part.
This commit is contained in:
parent
13f5aa81e3
commit
a30e364f1a
4 changed files with 10 additions and 2 deletions
|
@ -420,10 +420,14 @@ struct Formatter<FixedPoint<precision, Underlying>> : StandardFormatter {
|
|||
m_width = m_width.value_or(0);
|
||||
m_precision = m_precision.value_or(6);
|
||||
|
||||
bool is_negative = false;
|
||||
if constexpr (IsSigned<Underlying>)
|
||||
is_negative = value < 0;
|
||||
|
||||
i64 integer = value.ltrunk();
|
||||
constexpr u64 one = static_cast<Underlying>(1) << precision;
|
||||
u64 fraction_raw = value.raw() & (one - 1);
|
||||
return builder.put_fixed_point(integer, fraction_raw, one, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode);
|
||||
return builder.put_fixed_point(is_negative, integer, fraction_raw, one, base, upper_case, m_zero_pad, m_align, m_width.value(), m_precision.value(), m_fill, m_sign_mode, real_number_display_mode);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue