[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [analitza/imaginary] analitza: Fix complex division and add more tests
From:       Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date:       2014-06-15 5:13:54
Message-ID: E1Ww2lO-0004aa-II () scm ! kde ! org
[Download RAW message or body]

Git commit 10387c592f72f109f28fdeb97a1488599ab8ba8f by Percy Camilo Triveño Aucahuasi.
Committed on 15/06/2014 at 05:13.
Pushed by aucahuasi into branch 'imaginary'.

Fix complex division and add more tests

M  +1    -1    analitza/operations.cpp
M  +4    -0    analitza/tests/analitzatest.cpp

http://commits.kde.org/analitza/10387c592f72f109f28fdeb97a1488599ab8ba8f

diff --git a/analitza/operations.cpp b/analitza/operations.cpp
index f14e463..bb59b9c 100644
--- a/analitza/operations.cpp
+++ b/analitza/operations.cpp
@@ -173,7 +173,7 @@ Cn* reduceComplexComplex(enum Operator::OperatorType op, Cn *oper, complex<doubl
 			oper->setValue(a*b);
 			break;
 		case Operator::divide:
-			if(KDE_ISLIKELY(b.real()!=0. && b.imag()!=0.))
+			if(KDE_ISLIKELY(b.real()!=0. || b.imag()!=0.))
 				oper->setValue(a / b);
 			else
 				*correct=new QString(i18n("Cannot divide by 0."));
diff --git a/analitza/tests/analitzatest.cpp b/analitza/tests/analitzatest.cpp
index fcec6e8..28e0ce3 100644
--- a/analitza/tests/analitzatest.cpp
+++ b/analitza/tests/analitzatest.cpp
@@ -145,12 +145,16 @@ void AnalitzaTest::testTrivialEvaluate_data()
 	QTest::addColumn<QString>("result");
 	
 	QTest::newRow("simple value") << "2" << "2";
+	QTest::newRow("complex") << "i*5" << "5*i";
 	QTest::newRow("simple complex value") << "6*(2+i)" << "12+6*i";
 	QTest::newRow("complex irreductibility") << "i" << "i";
 	QTest::newRow("from complex value") << "i*i" << "-1";
 	QTest::newRow("from power complex") << "power(i, 2)" << "-1";
 	QTest::newRow("sin complex") << "sin(i)" << "1.17520119364*i";
 	QTest::newRow("cos complex") << "cos(5-9*i)" << "1149.26926545-3885.12187972*i";
+	QTest::newRow("complex*complex") << "(5.3-9.8*i)*(-6.2+3.7*i)" << "3.4+80.37*i";
+	QTest::newRow("simple complex/complex") << "i/i" << "1";
+	QTest::newRow("complex/complex") << "(9.3-5.4*i)/(3.6-9.5*i)" << "0.82143203178+0.667667861641*i";
 	QTest::newRow("simple addition") << "2+2" << "4";
 	QTest::newRow("simple addition with var") << "2+x" << "x+2";
 	QTest::newRow("minus irreductibility") << "-x" << "-x";
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic