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

            Bug ID: 96821
           Summary: ROUND changes integers when it should not
           Product: LibreOffice
           Version: 5.0.3.2 release
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: [email protected]
          Reporter: [email protected]

ROUND(x,0) should leave integers alone.  It does not.

A1=ROUND(B1,0)
B1=C1+1
C1=1024*1024*1024*1024*1024*4
A3=A1-(C1-1000)
B3=B1-(C1-1000)

I see B3=1001 [correct] and A3=1002 [wrong].

Without looking at the code I cannot be 100% certain, but the typical
cause of this trouble is that someone used

   x = std::floor (x + 0.5);

thinking that such code rounds to the nearest integer.  It does not.
For the value in B1 -- which is 2^52+1 -- as well as the next 2^50
odd numbers, the addition of 0.5 will actually add 1 since that is
the best approximation that fits in a double.

There is one more trouble number: the smallest number that is strictly
less than 0.5.  That should round to 0, but the addition yields 1.

The solution likely is to use std::round.  However, that function might
not so the desired thing for negative values.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to