[Libreoffice-bugs] [Bug 141200] Basic MOD operator must have a mention that it rounds its operands

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Thu Apr 1 15:08:40 UTC 2021


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

--- Comment #2 from Rafael Lima <rafael.palma.lima at gmail.com> ---
There seems to be a difference between MS VBA and LibreOffice Basic on how they
handle fractional remainders:

In Excel VBA, if you run (remainder is rounded to nearest integer):

Sub ExampleMod
    MsgBox 15.1 Mod 5 'Remainder = 0.1; Returns 0
    MsgBox 15.4 Mod 5 'Remainder = 0.4; Returns 0
    MsgBox 15.5 Mod 5 'Remainder = 0.5; Returns 1
    MsgBox 15.6 Mod 5 'Remainder = 0.6; Returns 1
    MsgBox 15.9 Mod 5 'Remainder = 0.9; Returns 1
    MsgBox 16 Mod 5 'Remainder = 1;  Returns 1
End Sub

And in LibreOffice Basic you get different results (even with the "Option
VBASupport 1" flag):

Sub ExampleMod
    MsgBox 15.1 Mod 5 'Remainder = 0.1; Returns 0
    MsgBox 15.4 Mod 5 'Remainder = 0.4; Returns 0
    MsgBox 15.5 Mod 5 'Remainder = 0.5; Returns 0
    MsgBox 15.6 Mod 5 'Remainder = 0.6; Returns 0
    MsgBox 15.9 Mod 5 'Remainder = 0.9; Returns 0
    MsgBox 16 Mod 5 'Remainder = 1;  Returns 1
End Sub

In summary, by looking at the code in [1] (using Mike's references here), this
difference is caused by LO Basic rounding operands before applying the MOD
operator.

I can add a note about that in the Help, as well as a few more examples to
illustrate it better.

-- 
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/20210401/16b24f9d/attachment-0001.htm>


More information about the Libreoffice-bugs mailing list