Bug 159421 - calc date function returns wrong value
Summary: calc date function returns wrong value
Status: RESOLVED DUPLICATE of bug 136615
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.6.4.1 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-29 03:39 UTC by Rich
Modified: 2024-01-29 04:53 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
wrongdate.ods (18.20 KB, application/octet-stream)
2024-01-29 03:43 UTC, Rich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rich 2024-01-29 03:39:45 UTC
Description:
Date function works with literal values but is unreliable with calculated values.  This occurred in both 7.6.2 and just now installed 7.6.4.

Steps to Reproduce:
1.PICK A CELL, A10, TYPE 4.15202
2.IN CELL B10 TYPE =INT(A10)
3.IN CELL C10 TYPE =A10-B10
IN CELL D10 TYPE =C10*100
IN CELL E10 TYPE =INT(D10)
IN CELL F10 TYPE =D10-E10
IN CELL G10 TYPE =F10*10000
IN CELL H10 TYPE =DATE(G10,B10,E10)

Actual Results:
IN H10: 04/15/2021

Expected Results:
IN H10: 04/15/2022


Reproducible: Always


User Profile Reset: Yes

Additional Info:
TOO BAD THE HELP INF REQUESTED CAN NOT BE COPIED!
Version: 7.6.4.1 (X86_64)
Build: e16e193f88cd6c0525a17fb7a...
Environment: CPU threads: 24; OS: Windows 10.0 build 22621
User interface: UI render: Skia/Raster; VCL: win
Locale: en-US (en-US); UI: en-US
Misc: Calc threaded
Comment 1 Rich 2024-01-29 03:43:02 UTC
Created attachment 192227 [details]
wrongdate.ods

it's a calc file
Comment 2 Stéphane Guillou (stragu) 2024-01-29 04:51:07 UTC
Thanks for the report. I see the same in your sample document.

Unfortunately, this is likely due to floating-point arithmetic imprecision common to many tools.

If you use in cell G16 the following formula instead:

=ROUND(F16*10000)

... the date will be as expected.

You can also see how the DATE() formula will handle a value that is just under the target value, try this:

=DATE(2021.9999999,4,15)

See this help page: https://help.libreoffice.org/latest/en-US/text/scalc/01/calculation_accuracy.html

There is an open report to improve the situation, so I will mark as duplicate as that one.

*** This bug has been marked as a duplicate of bug 136615 ***
Comment 3 Mike Kaganski 2024-01-29 04:53:51 UTC
(In reply to Rich from comment #0)
> Additional Info:
> TOO BAD THE HELP INF REQUESTED CAN NOT BE COPIED!

??? The Help->About dialog has a *button* to copy the data to clipboard, immediately next to "Version information" words, with a tooltip saying "Copy all version information in English".