mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:17:45 +00:00
AK+LibPDF: Make Format print floats in a roundtrip-safe way by default
Previously we assumed a default precision of 6, which made the printed values quite odd in some cases. This commit changes that default to print them with just enough precision to produce the exact same float when roundtripped. This commit adds some new tests that assert exact format outputs, which have to be modified if we decide to change the default behaviour.
This commit is contained in:
parent
26a5d84d91
commit
78c04cb8b2
4 changed files with 193 additions and 9 deletions
22
AK/Format.h
22
AK/Format.h
|
@ -238,15 +238,16 @@ public:
|
|||
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
||||
RealNumberDisplayMode = RealNumberDisplayMode::Default);
|
||||
|
||||
ErrorOr<void> put_f64(
|
||||
double value,
|
||||
template<OneOf<f32, f64> T>
|
||||
ErrorOr<void> put_f32_or_f64(
|
||||
T value,
|
||||
u8 base = 10,
|
||||
bool upper_case = false,
|
||||
bool zero_pad = false,
|
||||
bool use_separator = false,
|
||||
Align align = Align::Right,
|
||||
size_t min_width = 0,
|
||||
size_t precision = 6,
|
||||
Optional<size_t> precision = {},
|
||||
char fill = ' ',
|
||||
SignMode sign_mode = SignMode::OnlyIfNeeded,
|
||||
RealNumberDisplayMode = RealNumberDisplayMode::Default);
|
||||
|
@ -265,6 +266,21 @@ public:
|
|||
|
||||
private:
|
||||
StringBuilder& m_builder;
|
||||
|
||||
#ifndef KERNEL
|
||||
ErrorOr<void> put_f64_with_precision(
|
||||
double value,
|
||||
u8 base,
|
||||
bool upper_case,
|
||||
bool zero_pad,
|
||||
bool use_separator,
|
||||
Align align,
|
||||
size_t min_width,
|
||||
size_t precision,
|
||||
char fill,
|
||||
SignMode sign_mode,
|
||||
RealNumberDisplayMode);
|
||||
#endif
|
||||
};
|
||||
|
||||
class TypeErasedFormatParams {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue