Bug 93408 - ACOS Function returns erroneous output when referencing calculated cell value
Summary: ACOS Function returns erroneous output when referencing calculated cell value
Status: CLOSED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.4.0.3 release
Hardware: Other All
: medium major
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-13 11:26 UTC by Gautam Samant
Modified: 2016-06-27 10:16 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
Spreadsheet attached to demonstrate the bug (8.56 KB, application/vnd.oasis.opendocument.spreadsheet)
2015-08-13 11:26 UTC, Gautam Samant
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gautam Samant 2015-08-13 11:26:44 UTC
Created attachment 117887 [details]
Spreadsheet attached to demonstrate the bug

Problem Description

Value of Cell C1 is 1.15
Value of Cell A2 is 2.2
Cell B2 is A2+0.1 (Value = 2.3)
Value of Cell B3 is 2.3

Cell C2 = ACOS(1-B2/C1) 
i.e. ACOS(-1) it should return 3.14159...
Returns #VALUE!

Cell C3 = ACOS(1-B3/C1)
i.e. ACOS(-1)
Returns 3.14159... correctly.

Typing "2.3" in Cell B2 returns 3.14159 in cell C2 correctly.

Tested on following
Mac OS X with LibreOffice 5.0.0.5
Windows 7 with LibreOffice 4.4.0.3
Both have same bug.
Comment 1 Alex Thurgood 2015-08-13 14:04:39 UTC
Confirming on LO 5.0.0.2

OSX 10.10.4
Comment 2 Eike Rathke 2016-06-27 10:15:48 UTC
As usual, this is due to binary representation of floating point values. 2.2 and 0.1 have no exact representation and are more like 2.2000000000000002 and 0.10000000000000001 which add up to 2.3000000000000003; 1.15 is more like 1.1499999999999999 so the division result in C2 is 2.0000000000000004 and the subtraction result is -1.0000000000000004, which is an invalid argument to ACOS().

In cell C3 the division is around 2.2999999999999998 / 1.1499999999999999 with result 2, so 1-2=-1 is a good argument to ACOS().

Btw, Excel and Gnumeric show the same behavior.
We likely won't "fix" this.

To prevent this problem values have to be rounded at strategic places, e.g. in cell B2 instead of =A2+0.1 use =ROUND(A2+0.1,1) or round only the argument in cell C2 according to the expected decimals =ACOS(ROUND(1-B2/C1,2)), or even rounding to 12 decimals will work in this case. Your mileage may vary..