Bug 125676 - Cosinus wrong value
Summary: Cosinus wrong value
Status: CLOSED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.2.1.1 rc
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-04 07:54 UTC by abra01
Modified: 2019-06-05 16:10 UTC (History)
4 users (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 abra01 2019-06-04 07:54:49 UTC
Description:
Cos(pi()/2) returns 6,12323399573677E-17, but should return 0


Steps to Reproduce:
1. put to cell formula =cos(pi()/2)
2.
3.

Actual Results:
Cos(pi()/2) returns 6,12323399573677E-17

Expected Results:
cos(pi()/2) should return 0


Reproducible: Always


User Profile Reset: No



Additional Info:
OpenGL is off, OpenCL is ON and supported by hardware (nvidia quadro K1000M)
Comment 1 Xisco Faulí 2019-06-04 10:19:37 UTC
Reproduced in

Version: 6.3.0.0.beta1+
Build ID: 4abdaf4afb2245d404f6709124b3c627b07b8a3c
CPU threads: 4; OS: Linux 4.15; UI render: default; VCL: gtk3; 
Locale: ca-ES (ca_ES.UTF-8); UI-Language: en-US
Calc: threaded

and back to

LibreOffice 3.3.0 
OOO330m19 (Build:6)
tag libreoffice-3.3.0.4

@Eike, @Winfried, I thought you might be interested in this issue...
Comment 2 Tomaz Vajngerl 2019-06-04 10:20:13 UTC
Nope, that's correct and expected. Calc (or better computers in general) doesn't calculate with infinite precision (it uses floating points internally) so there are cases, where a calculation will produce an (rounding) error. 

So in cases like this you need to round things to the nearest decimal (=ROUND) - with that you also define how much precision you can tolerate.
Comment 3 Xavier Van Wijmeersch 2019-06-04 10:24:21 UTC
Thank you for reporting the bug but i cannot reproduce with

Version: 6.2.4.2
Build ID: 2412653d852ce75f65fbfa83fb7e7b669a126d64
CPU threads: 8; OS: Linux 4.19; UI render: default; VCL: gtk3; 
Locale: nl-BE (en_US.UTF-8); UI-Language: en-US
Calc: threaded

Version: 6.4.0.0.alpha0+
Build ID: c27e92b29efe573e2cda9844e9ca38965f502443
CPU threads: 8; OS: Linux 4.19; UI render: default; VCL: gtk3; 
Locale: nl-BE (en_US.UTF-8); UI-Language: en-US
Calc: threaded

can reproduce with 6.1 ==> 6.2.3.2

Can you upgrade LO to 6.2.4.2 and retest
Comment 4 abra01 2019-06-04 11:32:32 UTC
cos(pi()/2) = sin(0)
but sin(0) returns 0
and cos(pi()/2) returns 6,12323399573677E-17
Comment 5 Regina Henschel 2019-06-04 11:53:59 UTC
Please notice, that spreadsheets always do mathematics numerically. If you need symbolic mathematics, a spreadsheet is the wrong tool. In that case you should use a computer algebra system.
Comment 6 abra01 2019-06-04 12:09:10 UTC
It was an example. An answer to @Tomaz Vajngerl that it is not correct. 
If you put formula =sin(0) calc will return 0, but if you put formula =cos(pi()/2) you will get 6,12323399573677E-17

@Regina Henschel
It is treated purely numerically. 

@all
cos(pi()/2) = sin(0)
This is not symbolic calculation, this is paradigm. If you write this paradigm as  formula then it will return FALSE, but should be TRUE
Other tested formula was =cos(pi()/2)-sin(0), it will return -6,12323399573677E-17 , but should return 0.
Comment 7 abra01 2019-06-04 12:29:05 UTC
(In reply to Xavier Van Wijmeersch from comment #3)
> Thank you for reporting the bug but i cannot reproduce with
> 
> Version: 6.2.4.2
> Build ID: 2412653d852ce75f65fbfa83fb7e7b669a126d64
> CPU threads: 8; OS: Linux 4.19; UI render: default; VCL: gtk3; 
> Locale: nl-BE (en_US.UTF-8); UI-Language: en-US
> Calc: threaded
> 
> Version: 6.4.0.0.alpha0+
> Build ID: c27e92b29efe573e2cda9844e9ca38965f502443
> CPU threads: 8; OS: Linux 4.19; UI render: default; VCL: gtk3; 
> Locale: nl-BE (en_US.UTF-8); UI-Language: en-US
> Calc: threaded
> 
> can reproduce with 6.1 ==> 6.2.3.2
> 
> Can you upgrade LO to 6.2.4.2 and retest

Upgraded, tested and reproduced with 6.2.4.2
Comment 8 Tomaz Vajngerl 2019-06-04 13:05:45 UTC
(In reply to abra01 from comment #6)
> It was an example. An answer to @Tomaz Vajngerl that it is not correct. 
> If you put formula =sin(0) calc will return 0, but if you put formula
> =cos(pi()/2) you will get 6,12323399573677E-17

sin(0) is 0 because 0 can be represented exactly in a computer. Pi can't - it's a irrational number and is in a computer an approximate constant to the number of available precision of the floating point type. So then you divide that approximation by 2 which again deviates from the true value of pi/2. Lastly cos in computer is also a function that's computed numerically (calculating a Taylor series if I remember correctly) and has an error. Mostly this is not visible and pretty much irrelevant because the error is small, but sometimes (like in this) the result is surprising, but as I said - expected.
Comment 9 Tomaz Vajngerl 2019-06-04 13:09:02 UTC
There have been bugs like this in the past, but we can't do nothing about it.

BTW excel produces the same error, as it too is using IEEE 754 floating point numbers in the calculation core.