Bug 393487 - range(0, 1, 0.2) fails test on x86 (misses 1)
Summary: range(0, 1, 0.2) fails test on x86 (misses 1)
Status: RESOLVED FIXED
Alias: None
Product: analitza
Classification: Frameworks and Libraries
Component: core (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-25 05:59 UTC by A. Wilcox (awilfox)
Modified: 2018-06-01 12:42 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description A. Wilcox (awilfox) 2018-04-25 05:59:43 UTC
I'm the KDE maintainer for the Adélie Linux distro, a newer distribution (based on Alpine) that uses the musl libc.  While building analitza 17.12.2 for the 32-bit x86 architecture:


********* Start testing of CommandsTest *********
Config: Using QtTest library 5.9.3, Qt 5.9.3 (i386-little_endian-ilp32 shared (dynamic) release build; by GCC 6.4.0)
PASS   : CommandsTest::initTestCase()
PASS   : CommandsTest::testCorrect(simple range)
PASS   : CommandsTest::testCorrect(range(a,b))
FAIL!  : CommandsTest::testCorrect(range(a,b)) Compared values are not the same
   Actual   (last.toString()): "list { 0, 0.2, 0.4, 0.6, 0.8 }"
   Expected (result)         : "list { 0, 0.2, 0.4, 0.6, 0.8, 1 }"
   Loc: [/usr/src/packages/user/analitza/src/analitza-17.12.2/analitza/tests/commandstest.cpp(422)]


This is the only test that fails.  Trying a simple C program:

#include <stdio.h>

int main(void)
{
        for(double x = 0.0; x <= 1.0; x += 0.2)
                printf("%.02f\n", x);
        return 0;
}


does produce the intended result:

0.00
0.20
0.40
0.60
0.80
1.00


so it doesn't seem like the architecture itself is the problem.  I will note that Analitza passes its test suite successfully on x86_64, 32-bit PowerPC, and 64-bit PowerPC.  I'm not sure how else to help debug this failure.
Comment 1 Aleix Pol 2018-05-28 00:50:34 UTC
Thank you very much for bringing up this issue

The code that controls this is the loop in listcommands.cpp:73. 
Having a way to reproduce this would be interesting, it definitely looks like double being fussy.

Maybe you can try applying this and tell me if it works?
Another thing you could do is providing a docker image where I can test this.

diff --git a/analitza/commands/listcommands.cpp b/analitza/commands/listcommands.cpp
index b77f49a9..2885169a 100644
--- a/analitza/commands/listcommands.cpp
+++ b/analitza/commands/listcommands.cpp
@@ -69,8 +69,9 @@ Expression RangeCommand::operator()(const QList< Analitza::Expression >& args)
     
     Analitza::List *seq = new Analitza::List;
         
-    for (double x = a; x <= b; x += h)
+    for (double x = a; x < b || qFuzzyCompare(x, b); x += h) {
         seq->appendBranch(new Analitza::Cn(x));
+    }
     
     ret.setTree(seq);
Comment 2 A. Wilcox (awilfox) 2018-05-31 05:52:07 UTC
That patch fixes the test suite on 32-bit x86.

Any 32-bit x86 Docker image of Alpine or Adélie should allow you to easily repro this.
Comment 3 Aleix Pol 2018-06-01 12:42:32 UTC
Git commit 07dd33b04976dfa872ffa4c24bb17adc5803ee64 by Aleix Pol.
Committed on 01/06/2018 at 12:41.
Pushed by apol into branch 'master'.

Fix comparison in some 32bit machines

M  +2    -1    analitza/commands/listcommands.cpp

https://commits.kde.org/analitza/07dd33b04976dfa872ffa4c24bb17adc5803ee64