Bug 135103 - Decimal precision fail in addition
Summary: Decimal precision fail in addition
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.1.5.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Number-Format
  Show dependency treegraph
 
Reported: 2020-07-24 15:22 UTC by Javier
Modified: 2020-07-26 23:27 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Calc failing spreadsheet (12.99 KB, application/vnd.oasis.opendocument.spreadsheet)
2020-07-24 15:22 UTC, Javier
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Javier 2020-07-24 15:22:15 UTC
Created attachment 163482 [details]
Calc failing spreadsheet

Fail in addition of the following numbers.

-33912
-30925
-25085
-23600
-20000
-9645
-9184,51
-6650
-5000
-4833,8
-4220
-4123,03
-3000
-3000
-2786
-2500
-2000
0
0
0,03
0,03
0,03
0,03
0,06
0,1
0,17
0,18
0,2
0,21
0,36
0,41
0,42
0,42
0,57
0,71
0,72
0,75
0,75
0,81
0,81
0,81
0,81
0,81
0,83
0,83
0,83
0,83
0,83
0,83
0,83
0,83
0,83
1
1,23
1,72
1,79
2,58
3,34
3,38
7,5
348,74
697,09
1049,63
1261,89
2094,46
2260
2556
2789,19
4944,24
5700
9644,91
9697,92
9800
11968,21
15150
20111,78
25225,2
31123,26
34058,33


The result given by de spreadsheet is 56,7200000000084
The result in the "SUM" total en the lower right corner is 56,7199999998993

The real result must be 56,72. It's make fail conditionals formulas.

System specifications:

# dmidecode
(...)
Processor Information
	Socket Designation: Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
	Type: Central Processor
	Family: Core i7
	Manufacturer: Intel
	ID: A9 06 03 00 FF FB EB BF
	Signature: Type 0, Family 6, Model 58, Stepping 9

# uname -a
Linux jap 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 GNU/Linux

# dpkg -l libreoffice* | grep ii
ii  libreoffice-avmedia-backend-gstreamer 1:6.1.5-3+deb10u6 amd64        GStreamer backend for LibreOffice
ii  libreoffice-base                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- database
ii  libreoffice-base-core                 1:6.1.5-3+deb10u6 amd64        office productivity suite -- shared library
ii  libreoffice-base-drivers              1:6.1.5-3+deb10u6 amd64        Database connectivity drivers for LibreOffice
ii  libreoffice-calc                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- spreadsheet
ii  libreoffice-common                    1:6.1.5-3+deb10u6 all          office productivity suite -- arch-independent files
ii  libreoffice-core                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- arch-dependent files
ii  libreoffice-draw                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- drawing
ii  libreoffice-gtk3                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- GTK+ 3 integration
ii  libreoffice-help-common               1:6.1.5-3+deb10u6 all          office productivity suite -- common files for LibreOffice help
ii  libreoffice-help-en-us                1:6.1.5-3+deb10u6 all          office productivity suite -- English_american help
ii  libreoffice-help-es                   1:6.1.5-3+deb10u6 all          office productivity suite -- Spanish help
ii  libreoffice-impress                   1:6.1.5-3+deb10u6 amd64        office productivity suite -- presentation
ii  libreoffice-java-common               1:6.1.5-3+deb10u6 all          office productivity suite -- arch-independent Java support files
ii  libreoffice-l10n-es                   1:6.1.5-3+deb10u6 all          office productivity suite -- Spanish language package
ii  libreoffice-math                      1:6.1.5-3+deb10u6 amd64        office productivity suite -- equation editor
ii  libreoffice-report-builder            1:6.1.5-3+deb10u6 all          LibreOffice component for building database reports
ii  libreoffice-report-builder-bin        1:6.1.5-3+deb10u6 amd64        LibreOffice component for building database reports -- libraries
ii  libreoffice-sdbc-firebird             1:6.1.5-3+deb10u6 amd64        Firebird SDBC driver for LibreOffice
ii  libreoffice-sdbc-hsqldb               1:6.1.5-3+deb10u6 amd64        HSQLDB SDBC driver for LibreOffice
ii  libreoffice-sdbc-postgresql           1:6.1.5-3+deb10u6 amd64        PostgreSQL SDBC driver for LibreOffice
ii  libreoffice-style-colibre             1:6.1.5-3+deb10u6 all          office productivity suite -- colibre symbol style
ii  libreoffice-style-tango               1:6.1.5-3+deb10u6 all          office productivity suite -- Tango symbol style
ii  libreoffice-writer
Comment 2 Michael Warner 2020-07-25 03:49:32 UTC
(In reply to Mike Kaganski from comment #1)
> https://wiki.documentfoundation.org/Faq/Calc/Accuracy

I understand the limitations of IEEE754, and why this is a frequently asked question. That said, one could argue that it would be more user friendly if the formatting of a cell containing an equation (and the sum in the corner) defaulted to the number of decimal places shown to the minimum (or maximum) number of decimal places entered in any referenced cell containing a number. In the example provided, it just doesn't make sense to display a result to 14 places when at most 2 are provided.
Comment 3 Mike Kaganski 2020-07-25 06:36:00 UTC
(In reply to Michael Warner from comment #2)
> That said, one could argue that it would be more user friendly if
> the formatting of a cell containing an equation (and the sum in the corner)
> defaulted to the number of decimal places shown to the minimum (or maximum)
> number of decimal places entered in any referenced cell containing a number.
> In the example provided, it just doesn't make sense to display a result to
> 14 places when at most 2 are provided.

That is over-simplification. So for this formula:

> = <cell with 1> + <cell with 10> ^ <cell with -5>

all cells are shown with default formatting; all are whole numbers. Are you telling we need to show "1" instead of "1.00001"?

It's very difficult to come with a reasonable default precision (and analyzing the formula, taking into account display format, with its optional digits "#", display of multiples of 1000, scientific notation, percents, etc, may be very expensive and error-prone); IIRC Eike ~recently changed the default to "show as many as fit in column", but I may be wrong.
Comment 4 Javier 2020-07-25 17:10:09 UTC
(In reply to Michael Warner from comment #2)
> (In reply to Mike Kaganski from comment #1)
> > https://wiki.documentfoundation.org/Faq/Calc/Accuracy
> 
> I understand the limitations of IEEE754, and why this is a frequently asked
> question. That said, one could argue that it would be more user friendly if
> the formatting of a cell containing an equation (and the sum in the corner)
> defaulted to the number of decimal places shown to the minimum (or maximum)
> number of decimal places entered in any referenced cell containing a number.
> In the example provided, it just doesn't make sense to display a result to
> 14 places when at most 2 are provided.

That's one of the problems. If your boss see this, probably he doubt about yours skills.

The other problem, every conditional must be formated before each calculation, like

=IF( ROUND( (<cell with 31000.99> - <cell with 32000.12>;2) = ROUND( <cell with -999.13>;2); "OK"; "FAIL" ) );

That's a very heavy issue, a lot of time, memory, CPU resource, bugs, etc.
Comment 5 Michael Warner 2020-07-26 14:53:57 UTC
(In reply to Javier from comment #4)

So, a few points here. 

The first is that I would like to bring to your attention this page:
https://www.libreoffice.org/community/get-involved/

Which begins with this:
>  Welcome! LibreOffice is developed by a friendly community,

Statements like :

> If your boss see this, probably he doubt about yours skills.

Are something I might expect on twitter or youtube, but not really in line with what I would expect from a "friendly community".

Second is:
> 
> The other problem, every conditional must be formated before each
> calculation, like
> 
> =IF( ROUND( (<cell with 31000.99> - <cell with 32000.12>;2) = ROUND( <cell
> with -999.13>;2); "OK"; "FAIL" ) );
> 

I was just talking about formatting for display. Proper rounding in comparisons of floating points is a whole other topic, also worthy of addressing, but not something I choose to argue about here.

> That's a very heavy issue, a lot of time, memory, CPU resource, bugs, etc.

Fair enough, and things that we as developers must worry about. But irrelevant to users who don't know (or care) about the details of floating point representation in computers and just want the spreadsheet to add up numbers and show the result the way they learned it in elementary school.

Third point is that you are the person who filed the original bug. I was trying to help by brainstorming a possible solution to what I thought was the problem you were reporting. But your response is confusing to me because it seems like you are arguing against fixing the bug you filed. That doesn't make sense, so I think there is some context or detail to this whole situation that I am not aware of or not picking up on here.
Comment 6 Michael Warner 2020-07-26 14:59:52 UTC
(In reply to Mike Kaganski from comment #3)
> (In reply to Michael Warner from comment #2)
> > That said, one could argue that it would be more user friendly if
> > the formatting of a cell containing an equation (and the sum in the corner)
> > defaulted to the number of decimal places shown to the minimum (or maximum)
> > number of decimal places entered in any referenced cell containing a number.
> > In the example provided, it just doesn't make sense to display a result to
> > 14 places when at most 2 are provided.
> 
> That is over-simplification. So for this formula:
> 
> > = <cell with 1> + <cell with 10> ^ <cell with -5>
> 
> all cells are shown with default formatting; all are whole numbers. Are you
> telling we need to show "1" instead of "1.00001"?

I'm not telling you you "need" to do anything. I can't tell you what to do. 

> 
> It's very difficult to come with a reasonable default precision (and
> analyzing the formula, taking into account display format, with its optional
> digits "#", display of multiples of 1000, scientific notation, percents,
> etc, may be very expensive and error-prone); IIRC Eike ~recently changed the
> default to "show as many as fit in column", but I may be wrong.

Difficult to get it right in all cases, but we might be able to get 80% of them right for 20% of the effort. I don't know, it was just a thought. Ignore it if you don't like it, I think I'm done with this thread.
Comment 7 Javier 2020-07-26 23:27:23 UTC
(In reply to Michael Warner from comment #5)
> (In reply to Javier from comment #4)
> 
> So, a few points here. 
> 
> The first is that I would like to bring to your attention this page:
> https://www.libreoffice.org/community/get-involved/
> 
> Which begins with this:
> >  Welcome! LibreOffice is developed by a friendly community,
> 
> Statements like :
> 
> > If your boss see this, probably he doubt about yours skills.
> 
> Are something I might expect on twitter or youtube, but not really in line
> with what I would expect from a "friendly community".
> 
> Second is:
> > 
> > The other problem, every conditional must be formated before each
> > calculation, like
> > 
> > =IF( ROUND( (<cell with 31000.99> - <cell with 32000.12>;2) = ROUND( <cell
> > with -999.13>;2); "OK"; "FAIL" ) );
> > 
> 
> I was just talking about formatting for display. Proper rounding in
> comparisons of floating points is a whole other topic, also worthy of
> addressing, but not something I choose to argue about here.
> 
> > That's a very heavy issue, a lot of time, memory, CPU resource, bugs, etc.
> 
> Fair enough, and things that we as developers must worry about. But
> irrelevant to users who don't know (or care) about the details of floating
> point representation in computers and just want the spreadsheet to add up
> numbers and show the result the way they learned it in elementary school.
> 
> Third point is that you are the person who filed the original bug. I was
> trying to help by brainstorming a possible solution to what I thought was
> the problem you were reporting. But your response is confusing to me because
> it seems like you are arguing against fixing the bug you filed. That doesn't
> make sense, so I think there is some context or detail to this whole
> situation that I am not aware of or not picking up on here.

Thanks a LOT for your time.
3 simples fact about me:
-English is not my language; sorry if I'm not clear.
-I understand about "friendly community". I'm part of Debian community for more than 15 years (I'm a 55 old grandpa, that learned programming with cards an holes).
-The complexity of actual programs are so far than my skills.

I just only wanted to mark something. I understand floating point more than you believe, I came from the time that memory and CPU cycles was VERY expensive; everything were made with logarithms.
I was using the spreadsheet for simple calculation, no more far than a single precision point number, only 2 decimal. For this reason, it was odd for me.

For me, the bug is closed.

In my country, we said "known problem, is not problem".

Thanks again.