[Libreoffice-bugs] [Bug 142922] New: Basic: Round VBA compatibility function implements wrong rounding mode

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Thu Jun 17 19:45:02 UTC 2021


https://bugs.documentfoundation.org/show_bug.cgi?id=142922

            Bug ID: 142922
           Summary: Basic: Round VBA compatibility function implements
                    wrong rounding mode
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Keywords: implementationError
          Severity: normal
          Priority: medium
         Component: BASIC
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: mikekaganski at hotmail.com

As explained in VBA documentation for Round [1]:

> This VBA function returns something commonly referred to as bankers rounding.

[MS-VBAL] [2] defined Banker's rounding as alternative name for
"round-to-even"; it is one of rounding modes defined in IEEE 754, its
recommended rounding mode for decimal [3].

[1] also provides some examples demonstrating the values returned bu VBA's
Round:

> ?Round(0.12335,4)
>  0,1234
> ?Round(0.12345,4)
>  0,1234
> ?Round(0.12355,4)
>  0,1236
> ?Round(0.12365,4)
>  0,1236

However, LibreOffice's Round function [4] implementation [5] does not implement
the required rounding mode. Executing the example calculations mentioned above
gives 0.1234, 0.1235, 0.1236, 0.1237.

FTR: we have a rtl_math_round function, that accepts a flag defining rounding
mode, rtl_math_RoundingMode_HalfEven among the possible values, which may be
used in the VBA function implementation.

[1]
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/round-function

[2]
https://docs.microsoft.com/en-us/openspecs/microsoft_general_purpose_programming_languages/ms-vbal/98152b5a-4d86-4acb-b875-66cb1f49433e

[3] https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules

[4]
https://help.libreoffice.org/7.2/en-US/text/sbasic/shared/03170000.html?DbPAR=BASIC

[5]
https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=86d298f8&mo=63707&fi=2377#2377

[6]
https://opengrok.libreoffice.org/xref/core/sal/rtl/math.cxx?r=49af7e22&mo=38462&fi=1130#1130

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20210617/81424266/attachment.htm>


More information about the Libreoffice-bugs mailing list