Bug 114295 - Calc addition is broken: 751.19+(-700.1) != 51.09
Summary: Calc addition is broken: 751.19+(-700.1) != 51.09
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
5.4.3.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-06 21:53 UTC by Nathan Shearer
Modified: 2017-12-13 18:13 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
screenshot of bad math (16.18 KB, image/png)
2017-12-06 21:53 UTC, Nathan Shearer
Details
math error (1.0213 + -1) (11.21 KB, application/vnd.oasis.opendocument.spreadsheet)
2017-12-07 15:40 UTC, Nathan Shearer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Shearer 2017-12-06 21:53:45 UTC
Created attachment 138256 [details]
screenshot of bad math

1) Create a new spreadsheet
2) In column A enter 751.19
3) In column B enter -700.1
4) In column C enter =A1+B2
5) resize column C to see the error

Does not exist in 5.1.1.3 on windows build 89f508ef3ecebd2cfb8e1def0f0ba9a803b88a6d
exists in libreoffice 5.4.2.2.0+ on gentoo x84
exists in libreoffice 5.2.3.3 on arm
exists in libreoffice 5.4.3.2 on windows x64 build 92a7159f7e4af62137622921e809f8546db437e5

This reminds me of the Pentium FDIV bug. This is just sad. At the very least a spreadsheet application should be able to perform basic addition...
Comment 1 MM 2017-12-06 23:58:15 UTC
This is normal, it's because the program rounds off the sum internally (15 numbers wide, int or float).
When using the option: options > LO Calc > Calculate > Limit decimals [....] to 2 it should work for you. Maybe in previous versions it was set to this option, but got changed somehow.
So not a bug.
Comment 2 XTR 2017-12-07 07:25:47 UTC
Does not repro with libreoffice 5.4.3.2 on windows x64 build 92a7159f7e4af62137622921e809f8546db437e5
even if manual set  Calculate > Limit decimals  to 3-8 digits
changed LO locale to English - no effect
may be system locale dependent..
Comment 3 Kevin Suo 2017-12-07 08:24:37 UTC
I do not reproduce with

版本:5.4.4.1
Build ID:da790616461e15a10c95a80eb8ef8ee7b726c114
CPU 线程:4; 操作系统:Linux 4.13; UI 渲染:默认; VCL: gtk2; 
区域语言:zh-CN (zh_CN.UTF-8); Calc: group

Version: 6.1.0.0.alpha0+
Build ID:9644f506ae31f1cacd6ab4c24b2591179791eebd
CPU 线程:4; 操作系统:Linux 4.13; UI 渲染:默认; VCL: gtk2; 
Locale: zh-CN (zh_CN.UTF-8); Calc: group threaded

@Nathan Shearer: Did you use a TDF build version, or did you build from source by yourself? If you build by yourself, what's the build options you have used?
Comment 4 Nathan Shearer 2017-12-07 15:40:10 UTC
Created attachment 138282 [details]
math error (1.0213 + -1)
Comment 5 Nathan Shearer 2017-12-07 15:48:10 UTC
Yesterday I was able to reproduce it by simply typing in those values and making the formula in column C without changing any cell formatting. I did double-click on the column width to autoresize the columns which is when the error became apparent.

Now, today I can't seem to reproduce the bug. I do have the spreadsheets with wrong values saved and attached one to this bug report. I'll try to reproduce it the originally way I encountered it which was to populate the spreadsheets from CSV files with those values.

I originally encountered the bug on 5.2.3.3 built on a Gentoo arm raspberry pi 2.
I suspected it might be related to the unusual architecture, so reproduced it on 5.4.2.2.0+ on Gentoo x64.
I then tried to reproduce it on an older 5.1.1.3 build 89f508ef3ecebd2cfb8e1def0f0ba9a803b88a6d on windows which was not affected.
However, after uninstalling 5.1.1.3 on windows and installing 5.4.3.2 x64 build 92a7159f7e4af62137622921e809f8546db437e5 on windows I was able to reproduce it again.

My locale on Windows is set to en-CA (en_CA) and my locale on Linux is set to en-US (en_US.utf8)
Comment 6 Eike Rathke 2017-12-13 18:13:21 UTC
It's a known fact in computer world that decimal floating point numbers can't be accurately represented as binary floating point numbers and specifically adding or subtracting numbers may introduce an error margin.

See also
https://support.microsoft.com/kb/78113
https://blogs.office.com/en-us/2008/04/10/understanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers
https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel

This is similar true in Calc.