Bug 86174 - logic error with mod() and int() function
Summary: logic error with mod() and int() function
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
4.2.4.2 release
Hardware: x86 (IA32) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Calc-Function Calculate
  Show dependency treegraph
 
Reported: 2014-11-12 00:52 UTC by Brian Prasse
Modified: 2024-11-19 03:16 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
sample_that_correct_math_is_possible_in_calc (11.47 KB, application/vnd.oasis.opendocument.spreadsheet)
2020-10-04 22:08 UTC, b.
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Prasse 2014-11-12 00:52:09 UTC
Mod(2.01,int(2.01))=0.01 returns false
Comment 1 m_a_riosv 2014-11-12 01:14:31 UTC
Hi @Brian, thanks for reporting.

Really not a bug, but a hardware limitation, please take a look to https://bugs.freedesktop.org/show_bug.cgi?id=50299#c4.
Comment 2 Robinson Tryon (qubit) 2014-11-12 01:19:29 UTC
Another symptom of floating-point arithmetic being imperfect.

If you bump-up precision to 20 places, you see:

Value:                  2.01000000000000000000
INT(Value):             2.00000000000000000000
MOD(Value, INT(Value)): 0.00999999999999979000

When you compare 0.01000000000000000000 and 0.00999999999999979000, Calc (correctly) says that they're not the same.

I'm not sure if Calc has a built-in EQUAL_WITHIN_TOLERANCE() function, but you can use this for the purpose:

=(ABS($CELL_OF_FIRST_VALUE - $CELL_OF_SECOND_VALUE) < 0.0000000000001)

Making sure that two values are less than 1e-12 different should be close enough for most purposes :-)

See:
Bug 67026 - Other: Limitations in Calc precision need to be documented
Comment 3 b. 2020-10-04 22:08:25 UTC
Created attachment 166070 [details]
sample_that_correct_math_is_possible_in_calc

@m.a.riosv: 

disagree ... see attached sheet, 

hardware limitation? no, weak, but doesn't forbid meaningful calculations, 

kohei: 

'So it's a hardware problem.' - the software is responsible for what it does with the hardware, 
 
'Anything we try to do at software level would be hacky and prone to other, more serious errors,' - anything? really anything??? who gives up can no longer win,  

'including significant performance impact.' - si, but hardware and performance improve steadily, this statement is 8 years old, thus outdated by a performance factor of 16, 

'IMO we should leave this alone.' - imho not, users won't let us alone with their correct questions about incorrect results, 

math is an exact science - tries to be - we should try to keep up ... 

this bug is! a bug as the result is mathematically incorrect, and it is! a bug as better results are possible, see attachement,
Comment 4 b. 2020-10-04 22:24:25 UTC
besides ... 50299 is! resolved / fixed ...
Comment 5 QA Administrators 2022-11-18 03:36:29 UTC Comment hidden (obsolete)
Comment 6 Roman Kuznetsov 2022-11-19 14:02:52 UTC
Still repro in

Version: 7.5.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: ddb8a1a282aae74c1cee3a5e1f446abd0c00b116
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: threaded
Comment 7 QA Administrators 2024-11-19 03:16:08 UTC
Dear Brian Prasse,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug