[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [analitza/imaginary] analitza: Add arg, real and imaginary operators for complex numbers
From: Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date: 2014-06-15 7:08:38
Message-ID: E1Ww4YQ-0006dy-N1 () scm ! kde ! org
[Download RAW message or body]
Git commit c915c57b72f044eee35699ea533c52afd086786d by Percy Camilo Triveño Aucahuasi.
Committed on 15/06/2014 at 07:08.
Pushed by aucahuasi into branch 'imaginary'.
Add arg, real and imaginary operators for complex numbers
M +6 -1 analitza/operations.cpp
M +3 -0 analitza/tests/analitzatest.cpp
http://commits.kde.org/analitza/c915c57b72f044eee35699ea533c52afd086786d
diff --git a/analitza/operations.cpp b/analitza/operations.cpp
index 09f7d5b..158e786 100644
--- a/analitza/operations.cpp
+++ b/analitza/operations.cpp
@@ -332,11 +332,16 @@ Cn* Operations::reduceUnaryComplex(Operator::OperatorType op, Cn* val, QString**
val->setValue(a>=0. ? a : -a);
break;
case Operator::conjugate:
- val->setValue(complex<double>(a.real(), -a.imag()));
+ val->setValue(std::conj(a));
break;
case Operator::arg:
+ val->setValue(std::arg(a));
+ break;
case Operator::real:
+ val->setValue(a.real());
+ break;
case Operator::imaginary:
+ val->setValue(a.imag());
break;
default:
*correct=new QString(i18n("Could not calculate a value %1", Operator(op).toString()));
diff --git a/analitza/tests/analitzatest.cpp b/analitza/tests/analitzatest.cpp
index 721f6c5..7e32178 100644
--- a/analitza/tests/analitzatest.cpp
+++ b/analitza/tests/analitzatest.cpp
@@ -157,6 +157,9 @@ void AnalitzaTest::testTrivialEvaluate_data()
QTest::newRow("complex/complex") << "(9.3-5.4*i)/(3.6-9.5*i)" << "0.82143203178+0.667667861641*i";
QTest::newRow("simple complex conjugate") << "conjugate(i)" << "-i";
QTest::newRow("complex conjugate") << "conjugate(-9.3+5.87*i)" << "-9.3-5.87*i";
+ QTest::newRow("complex arg") << "arg(i)" << "1.57079632679";
+ QTest::newRow("complex real part") << "real(45-9*i)" << "45";
+ QTest::newRow("complex imag part") << "imaginary(45-9*i)" << "-9";
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