Bug 143575 - Strings are not converted correctly to their nearest double representation
Summary: Strings are not converted correctly to their nearest double representation
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.3.0 target:7.2.3
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-28 08:22 UTC by Andreas Heinisch
Modified: 2021-09-30 13:20 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Heinisch 2021-07-28 08:22:10 UTC
Description:
Consider the following double in BASIC: 691.2

The nearest double representation is according to IEEE 754 is 691.200000000000045474735088646411895751953125

Currently, a double value will be converted in basic/source/sbx/sbxdbl.cxx using 17 significant digits with ImpCvtNum( n, 17, *p->pOUString, bCoreString ); 

Steps to Reproduce:
Insert the following macro:
Sub Test
    MsgBox 691.2
End Sub

Actual Results:
691.2000000000001

Expected Results:
691.2


Reproducible: Always


User Profile Reset: No



Additional Info:
This bug is a follow up of 107953. Prior versions are not affected due to reduced precision.
Comment 1 Mike Kaganski 2021-07-28 08:34:06 UTC
This in fact may relate both to conversion of string to double, or double to string (so that a correctly imported number might be represented using wrong digits). See also tdf#130725. I wonder when we will be able to use elementary string conversion functions from C++17 [1] and if they will help us in such a non-standard thing as Basic's import and formatting. Also interesting if tdf#143193 is related, with its unobvious non-standard extensions to LO usual number formatter code.

[1] https://en.cppreference.com/w/cpp/utility#Elementary_string_conversions
Comment 2 Commit Notification 2021-09-30 07:28:11 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ed166025123a403fbd679377387a45e097f09d6e

tdf#143575, tdf#143974 - Use rtl::math::doubleToUString to convert numbers to strings

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2021-09-30 09:34:53 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/8294268307d98d3ea04f18a2ed89212cec516845

tdf#143575, tdf#143974 - Remove custom precision format in BASIC

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2021-09-30 13:13:49 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/da0d6541b29f4dd3cd223e15be14dabc2704fb83

tdf#143575, tdf#143974 - Use rtl::math::doubleToUString to convert numbers to strings

It will be available in 7.2.3.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2021-09-30 13:20:10 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/bc2896c98795d356d2c1b690d431b94aebd5b5bb

tdf#143575, tdf#143974 - Remove custom precision format in BASIC

It will be available in 7.2.3.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.