diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-02-15 09:20:52 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-02-17 21:46:58 +0100 |
commit | 9eb9083ff2fdaeb96399a0830a4394de4e29ef64 (patch) | |
tree | 046cc63551286fb3e59c6b79ebeea505a23b2eb0 /external/dragonbox | |
parent | ee373f34ae1509e8d9fffaf4b5140ee9c35e8d41 (diff) |
Use Dragonbox to implement doubleTo*String*
This header-only library is accurate in decimal representation of
doubles; provides API that allows to create custom representation
- so it's possible to use custom decimal separators and grouping.
This allows to unify all corner cases: integers, numbers close to
DBL_MAX, up-rounding to the next decade.
Note that Dragonbox creates the shortest decimal representation
of the number, that is unambiguously convertible back to the same
number; thus it may hide trailing digits that are unneeded for
such conversion.
The functional changes are minimal, and beneficial:
1. Rounding numbers close to DBL_MAX now takes into account the
bEraseTrailingDecZeros argument, as it should, allowing to have
"1.8E+308" for rounding DBL_MAX to 2 decimals without trailing
zeroes, instead of previous "1.80E+308".
2. Incorrect rounding is fixed in some cases, e.g. 9.9999999999999929
rounded to 10 previously using rtl_math_DecimalPlaces_Max.
3. Representing the number in the shortest way may change display
of some printed numbers. E.g., 5th greatest double is represented
as "1.797693134862315E+308" instead of a bit longer, but giving
the same double on roundtrip, "1.7976931348623149E+308". This would
generally look better for some numbers similar to the famous 0.1,
where users would likely expect more "round" representation where
it's unambiguous (but we still truncate to 15 significant decimals
anyway - so there's no point in pretending to provide exact digits
for actual binary representation).
These are reflected in the unit tests affected by the change.
Change-Id: I05e20274a30eec499593ee3e9ec070e1269232a2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129948
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'external/dragonbox')
-rw-r--r-- | external/dragonbox/Module_dragonbox.mk | 16 | ||||
-rw-r--r-- | external/dragonbox/README | 4 | ||||
-rw-r--r-- | external/dragonbox/UnpackedTarball_dragonbox.mk | 14 |
3 files changed, 34 insertions, 0 deletions
diff --git a/external/dragonbox/Module_dragonbox.mk b/external/dragonbox/Module_dragonbox.mk new file mode 100644 index 000000000000..2ed608f1e5e8 --- /dev/null +++ b/external/dragonbox/Module_dragonbox.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Module_Module,dragonbox)) + +$(eval $(call gb_Module_add_targets,dragonbox,\ + UnpackedTarball_dragonbox \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/external/dragonbox/README b/external/dragonbox/README new file mode 100644 index 000000000000..28db2711b9e4 --- /dev/null +++ b/external/dragonbox/README @@ -0,0 +1,4 @@ +Dragonbox is available from [ https://github.com/jk-jeon/dragonbox ]. + +Used to convert a double to a decimal string, providing breakout of significand and exponent +as integers, allowing to create custom number representation (e.g., locale-specific). diff --git a/external/dragonbox/UnpackedTarball_dragonbox.mk b/external/dragonbox/UnpackedTarball_dragonbox.mk new file mode 100644 index 000000000000..c483f19a3c56 --- /dev/null +++ b/external/dragonbox/UnpackedTarball_dragonbox.mk @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_UnpackedTarball_UnpackedTarball,dragonbox)) + +$(eval $(call gb_UnpackedTarball_set_tarball,dragonbox,$(DRAGONBOX_TARBALL))) + +# vim: set noet sw=4 ts=4: |