Bug 147089 - Incorrect handling of right-hand argument to "\" Integral Division BASIC operator
Summary: Incorrect handling of right-hand argument to "\" Integral Division BASIC oper...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.4.0 target:7.3.2
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2022-01-31 14:22 UTC by Mike Kaganski
Modified: 2022-02-22 10:22 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2022-01-31 14:22:27 UTC
Consider the code:

Sub testIntDiv()
  MsgBox 5 / 4 & Chr(10) & _
         5 \ 4 & Chr(10) & _
         7 / 4 & Chr(10) & _
         7 \ 4 & Chr(10) & _
         7 / 3.5 & Chr(10) & _
         7 \ 3.5 & Chr(10) & _
         6.5 / 3.5 & Chr(10) & _
         6.5 \ 3.5 & Chr(10)
End Sub

It is intended to give the following result:

1,25
1
1,75
1
2
1
1,85714285714286
1

Instead, it produces

1,25
1
1,75
1
2
2
1,85714285714286
2

See how '7 \ 3.5' and '6.5 \ 3.5' produce 2 instead of expected 1 - according to the proper "first round both operands to nearest integer, then return truncated result of division". Note that even using 3.9 instead of 3.5 gives the same wrong result.

This also deviates from VBA.
Comment 1 Commit Notification 2022-02-21 22:11:12 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3ba8b56b32c203326b776b940d20b16eb2340835

tdf#147089 - Round Integral Division (IDIV) literals to Integer values

It will be available in 7.4.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 2 Commit Notification 2022-02-22 10:22:54 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/1f0c42c3e91378d6e03e854711aa389f4c215a96

tdf#147089 - Round Integral Division (IDIV) literals to Integer values

It will be available in 7.3.2.

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.