Bug 271251

Summary: XOR function has been implemented wrongly
Product: [Applications] calligrasheets Reporter: Freek de Kruijf <freekdekruijf>
Component: generalAssignee: Calligra Sheets (KSpread) Bugs <calligra-sheets-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: inge
Priority: NOR    
Version: 2.2   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: XOR fix

Description Freek de Kruijf 2011-04-18 23:27:16 UTC
Version:           2.2 (using KDE 4.5.5) 
OS:                Linux

The description of the XOR function in messages/calligra/tables.pot is:

The XOR() function returns False if the number of True values is even. 
Otherwise it returns True. It returns an error if any argument is an error.

A better description would be:

The XOR() function executes per two Boolean parameters, starting at the left, 
an XOR, reducing these two parameters to one and repeats that until there is only one result. The function XOR(True;True) = XOR (False;False) = False; XOR(True;False) = XOR(False;True) = True. It returns an error if any argument is an error.

The implementation is wrong.
Entering =XOR(False;True;True;True) in a cell should return True, however it returns False. According to the above description the result should be True if the number of True parameters is uneven. This number is 3, so it should be True. Also the suggested description has True as the outcome of the function.

Reproducible: Always

Steps to Reproduce:
See above.

Actual Results:  
False

Expected Results:  
True

The suggested description is more close to a mathematical oriented user.
Comment 1 Christoph Feck 2011-04-23 19:15:52 UTC
Created attachment 59250 [details]
XOR fix

This should fix it (but untested).
Comment 2 Freek de Kruijf 2011-04-23 21:40:52 UTC
Are you serious to produce and release code that you did not test on proper functioning?
Comment 3 Christoph Feck 2011-04-24 18:54:58 UTC
The change is a no-brainer, why don't you verify the fix? You reported the bug, so you should know how to trigger it. I have never used calligra-tables, so I don't even know how I can test the XOR function.
Comment 4 Freek de Kruijf 2011-04-26 09:24:38 UTC
I don't know when the new version with the patch arrives in an update to my distribution, openSUSE. It is only at that moment that I can test the change.
Tables is just the new name for KSpread, and it works as a spreadsheet application. To test you only need to enter "=XOR(False;True;True;True)" without the quotes in a cell and observe the outcome; should be True. Add another True as argument and the result should be False, etc.
Comment 5 Inge Wallin 2011-06-03 16:48:12 UTC
Git commit e6c0736543820b1fe4a73c89eb1f85284103f8ef by Inge Wallin.
Committed on 03/06/2011 at 16:44.
Pushed by ingwa into branch 'master'.

Fix bug 271251: XOR function has been implemented wrongly

BUG:271251

The analysis By Christoph Feck in commnet #1 is spot on, and so was
the attached patch. I just changed it a tiny amount.  Thank you very
much.

It's a bit embarrassing that we let this fundamental bug through.

M  +2    -2    tables/functions/logic.cpp     

http://commits.kde.org/calligra/e6c0736543820b1fe4a73c89eb1f85284103f8ef
Comment 6 Inge Wallin 2011-06-03 16:50:23 UTC
I forgot to write: This fix will be in 2.4 snapshot 2, which is released on June 14th according to http://community.kde.org/Calligra/Schedules/2.4/Release_Plan .