Bug 89603 - MOD operator wrong, or else does not work as documented
Summary: MOD operator wrong, or else does not work as documented
Status: RESOLVED DUPLICATE of bug 84435
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.4.0.2 rc
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-24 01:13 UTC by Jim Avera
Modified: 2015-02-24 20:34 UTC (History)
1 user (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 Jim Avera 2015-02-24 01:13:05 UTC
The MOD operator documentation in online help contains the following:
" Example:
  Sub ExampleMod
    Print 10 Mod 2.5 ' returns 0    
    ...
  End Sub"

However 10 Mod 2.5 actually returns 1, not 0.

*Either the code or the documentation is wrong.* FWIW OO 4.1.1 behaves the same.

The "Libre Office Basic Guide (v. 3)" documents
   MOD - modulo operation (calculation of the remainder of a division)

Nowhere is there any mention of rounding or truncation of the arguments, but the second arg appears to be munged somehow -- but not consistently.
10 Mod 2.5 returns 1 (contrary to the docs), which is what you would expect if 2.5 were rounded to 3.  However 10 Mod 0.9 produces a "Divide by zero" error, which implies truncation toward zero rather than rounding.

STEPS TO REPRODUCE:

1. Open the Basic IDE on some module to allow entering new code
(For example:
   Open a new spreadsheet; Tools->Macros->Organize Macros->LibreOffice Basic
   Click "Untitled 1" (or the document name); Click NEW; IDE Editor opens
)  

2. Paste the following test sub at the top of the module:

     sub bugtest
       print "10 Mod 2.5 = " ; 10 Mod 2.5
     end sub

3. Press F5 or click the "Run Basic" icon

ACTUAL RESULT: 1

DOCUMENTED RESULT: 0
Comment 1 Julien Nabet 2015-02-24 20:33:30 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.
Comment 2 Julien Nabet 2015-02-24 20:34:15 UTC

*** This bug has been marked as a duplicate of bug 84435 ***