diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/analyzer.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/analyzer.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/analyzer.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/analyzer.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -37,6 +37,7 @@ #include "substituteexpression.h" #include "expressionstream.h" #include "matrix.h" +#include "commands/realpower.h" #include "commands/listcommands.h" #include "commands/vectorcommands.h" #include "commands/matrixcommands.h" @@ -163,6 +164,7 @@ void Analyzer::registerBuiltinMethods() { + m_builtin.insertFunction(RealPower::id, RealPower::type, new RealPower); m_builtin.insertFunction(RangeCommand::id, RangeCommand::type, new RangeCommand); m_builtin.insertFunction(VectorCommand::id, VectorCommand::type, new VectorCommand); m_builtin.insertFunction(MatrixCommand::id, MatrixCommand::type, new MatrixCommand); @@ -1102,8 +1104,7 @@ List::iterator it=l->begin(), itEnd=l->end(); for(; it!=itEnd; ++it) { - QVector args=QVector(1, *it); - *it = calcCallFunction(f, args, f); + *it = calcCallFunction(f, { *it }, f); } delete f; diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/CMakeLists.txt analitza-19.12.3+p20.04+git20200418.1007/analitza/CMakeLists.txt --- analitza-19.12.3+p20.04+git20200305.1807/analitza/CMakeLists.txt 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/CMakeLists.txt 2020-04-18 10:07:59.000000000 +0000 @@ -40,6 +40,7 @@ substituteexpression.cpp transformation.cpp + commands/realpower.cpp commands/listcommands.cpp commands/vectorcommands.cpp commands/matrixcommands.cpp diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/commands/realpower.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/commands/realpower.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/commands/realpower.cpp 1970-01-01 00:00:00.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/commands/realpower.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -0,0 +1,47 @@ +/************************************************************************************* + * Copyright (C) 2020 Aleix Pol Gonzalez * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#include "realpower.h" + +#include + +#include "expression.h" +#include "list.h" +#include "value.h" + +using namespace Analitza; + +const QString RealPower::id = QStringLiteral("realpower"); +const ExpressionType RealPower::type = ExpressionType(ExpressionType::Lambda) + .addParameter(ExpressionType::Value) + .addParameter(ExpressionType::Value) + .addParameter(ExpressionType::Value); + +Expression RealPower::operator()(const QList& args) +{ + const auto x = args.constFirst().toReal().complexValue(); + const auto r = args.constLast().toReal().complexValue(); + + double sign = x.real() >= 0 ? 1 : -1; + + Cn reta; + reta.setValue(sign * std::pow(sign * x, r)); + + qDebug() << "retaaaaa" << reta.toString(); + return Expression(reta); +} diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/commands/realpower.h analitza-19.12.3+p20.04+git20200418.1007/analitza/commands/realpower.h --- analitza-19.12.3+p20.04+git20200305.1807/analitza/commands/realpower.h 1970-01-01 00:00:00.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/commands/realpower.h 2020-04-18 10:07:59.000000000 +0000 @@ -0,0 +1,33 @@ +/************************************************************************************* + * Copyright (C) 2020 Aleix Pol Gonzalez * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * + *************************************************************************************/ + +#ifndef REALPOWER_H +#define REALPOWER_H + +#include "builtinmethods.h" + +class RealPower: public Analitza::FunctionDefinition +{ +public: + virtual Analitza::Expression operator()(const QList< Analitza::Expression >& args) override; + + static const QString id; + static const Analitza::ExpressionType type; +}; + +#endif // REALPOWER_H diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/htmlexpressionwriter.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/htmlexpressionwriter.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/htmlexpressionwriter.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/htmlexpressionwriter.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -95,22 +95,25 @@ QString realpart; QString imagpart; bool realiszero = false; - if (qAbs(var->complexValue().real()) > MIN_PRINTABLE_VALUE) - realpart = QString::number(var->complexValue().real(), 'g', 12); + const auto complex = var->complexValue(); + if (qAbs(complex.real()) > MIN_PRINTABLE_VALUE) + realpart = QString::number(complex.real(), 'g', 12); else realiszero = true; - - if (var->complexValue().imag() != 1 && var->complexValue().imag() != -1) { - if (qAbs(var->complexValue().imag()) > MIN_PRINTABLE_VALUE) { - if (!realiszero && var->complexValue().imag()>0.) - realpart += QLatin1String("+"); - imagpart = QString::number(var->complexValue().imag(), 'g', 12); + + if (!qFuzzyCompare(qAbs(complex.imag()), 1)) { + if (qAbs(complex.imag()) > MIN_PRINTABLE_VALUE) { + if (!realiszero && complex.imag()>0.) + realpart += QLatin1Char('+'); + imagpart = QString::number(complex.imag(), 'g', 12); imagpart += QStringLiteral("*i"); } - } else { - if (var->complexValue().imag() == 1) + } else { + if (!realiszero) + realpart += QLatin1Char('+'); + if (qFuzzyCompare(complex.imag(), 1)) imagpart = QStringLiteral("i"); - else if (var->complexValue().imag() == -1) + else imagpart = QStringLiteral("-i"); } diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/operations.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/operations.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/operations.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/operations.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -59,9 +59,11 @@ oper->setValue(a - b); break; case Operator::power: - oper->setValue( b==2 ? a*a - : b<1 && b>-1 && a<0 ? pow(complex(a), complex(b)).real() - : pow(a, b)); + if (b<1 && b>-1 && a<0) { + oper->setValue(pow(complex(a), complex(b))); + } else { + oper->setValue(b==2 ? a*a : pow(a, b)); + } break; case Operator::rem: if(Q_LIKELY(floor(b)!=0.)) diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/polynomial.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/polynomial.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/polynomial.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/polynomial.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -197,7 +197,7 @@ Monomial imono(m_operator, *it, m_sign); bool added=false; - if(imono.second->isApply()) { + if(imono.second->isApply() && imono.first == 1) { Apply* a = static_cast(imono.second); Operator op=a->firstOperator(); if(a->firstOperator()==m_operator diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/polynomial.h analitza-19.12.3+p20.04+git20200418.1007/analitza/polynomial.h --- analitza-19.12.3+p20.04+git20200305.1807/analitza/polynomial.h 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/polynomial.h 2020-04-18 10:07:59.000000000 +0000 @@ -85,7 +85,7 @@ private: void addMonomial(const Monomial& m); void addValue(Analitza::Object* value); - void simpScalars(bool m_firstValue); + void simpScalars(bool firstValue); QVector m_scalars; Operator m_operator; diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/stringexpressionwriter.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/stringexpressionwriter.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/stringexpressionwriter.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/stringexpressionwriter.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -111,25 +111,28 @@ QString realpart; QString imagpart; bool realiszero = false; - if (qAbs(var->complexValue().real()) > MIN_PRINTABLE_VALUE) - realpart = QString::number(var->complexValue().real(), 'g', 12); + const auto complex = var->complexValue(); + if (qAbs(complex.real()) > MIN_PRINTABLE_VALUE) + realpart = QString::number(complex.real(), 'g', 12); else realiszero = true; - - if (var->complexValue().imag() != 1 && var->complexValue().imag() != -1) { - if (qAbs(var->complexValue().imag()) > MIN_PRINTABLE_VALUE) { - if (!realiszero && var->complexValue().imag()>0.) + + if (!qFuzzyCompare(qAbs(complex.imag()), 1)) { + if (qAbs(complex.imag()) > MIN_PRINTABLE_VALUE) { + if (!realiszero && complex.imag()>0.) realpart += QLatin1Char('+'); - imagpart = QString::number(var->complexValue().imag(), 'g', 12); + imagpart = QString::number(complex.imag(), 'g', 12); imagpart += QStringLiteral("*i"); } - } else { - if (var->complexValue().imag() == 1) + } else { + if (!realiszero) + realpart += QLatin1Char('+'); + if (qFuzzyCompare(complex.imag(), 1)) imagpart = QStringLiteral("i"); - else if (var->complexValue().imag() == -1) + else imagpart = QStringLiteral("-i"); } - + return QVariant::fromValue(realpart+imagpart); } else diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/tests/analitzatest.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/tests/analitzatest.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/tests/analitzatest.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/tests/analitzatest.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -100,8 +100,9 @@ QTest::newRow("lambda") << "(x->x+2)(2)" << Cn(4.); QTest::newRow("lambda2") << "(x->3*x^2)(1)" << Cn(3.); QTest::newRow("lambda3") << "(x->x*sum(t:t=0..3))(2)" << Cn(12.); - QTest::newRow("imaginarypow") << "(-4)^(1/4)" << Cn(1.); + QTest::newRow("imaginarypow") << "(-4)^(1/4)" << Cn(1, 1); QTest::newRow("imaginaryroot") << "root(-4, 4)" << Cn(1.); + QTest::newRow("squareroot-1") << "(-1)^(1/2)" << Cn(0, 1); //comprehension QTest::newRow("sum.2bvars") << "sum(x*y : (x, y)=1..3)" << Cn(36.); @@ -668,6 +669,7 @@ QTest::newRow("poli4") << "-x-1-2-4" << "-x-7"; QTest::newRow("poli4.0") << "-x-y-z" << "-x-y-z"; QTest::newRow("poli4.1") << "minus(-x, 1, 2, 4)" << "-x-7"; + QTest::newRow("poli5") << "y+3*(x-1)" << "y+3*(x-1)"; // QTest::newRow("powerscomb") << "3**x*3**x" << "9^x"; QTest::newRow("no var") << "2+2" << "4"; QTest::newRow("simple") << "x+x" << "2*x"; diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/tests/builtintest.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/tests/builtintest.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/tests/builtintest.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/tests/builtintest.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -229,6 +229,8 @@ QTest::newRow("or") << (IN QStringLiteral("or(true, justcrash(33))")) << "true"; QTest::newRow("and1") << (IN QStringLiteral("and(false, true, justcrash(33))")) << "false"; QTest::newRow("or1") << (IN QStringLiteral("or(true, false, justcrash(33))")) << "true"; + + QTest::newRow("img-powers") << QStringList{"realpower(-8, 1/3)"} << "-2"; } void BuiltInTest::testCall() @@ -256,4 +258,19 @@ QCOMPARE(calc.toString(), output); else QCOMPARE(QStringLiteral("err"), output); + +// Expression eval; +// foreach(const QString& input, inputs) { +// Expression ei(input); +// if(!ei.isCorrect()) qDebug() << "error:" << ei.error(); +// QVERIFY(ei.isCorrect()); +// a.setExpression(ei); +// QVERIFY(a.isCorrect()); +// eval = a.evaluate(); +// } +// +// if(a.isCorrect()) +// QCOMPARE(eval.toString(), output); +// else +// QCOMPARE(QStringLiteral("err"), output); } diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/value.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/value.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/value.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/value.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -131,3 +131,13 @@ m_value = v.real(); } } + +constexpr bool ourFuzzyCompare(qreal a, qreal b) +{ + return qAbs(a - b) < std::numeric_limits::epsilon()*2; +} + +bool Cn::operator==(const Analitza::Cn& d) const{ + return ourFuzzyCompare(m_value, d.m_value) && ourFuzzyCompare(m_imaginaryPart, d.m_imaginaryPart); +} + diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/value.h analitza-19.12.3+p20.04+git20200418.1007/analitza/value.h --- analitza-19.12.3+p20.04+git20200305.1807/analitza/value.h 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/value.h 2020-04-18 10:07:59.000000000 +0000 @@ -119,7 +119,7 @@ /** * @returns whether @p d is equal than this object. */ - bool operator==(const Cn& d) const { return m_value==d.m_value && d.m_imaginaryPart==m_imaginaryPart; } + bool operator==(const Cn& d) const; /** * @returns whether @p d is less than this object. @@ -167,7 +167,7 @@ static Cn euler(); private: union { double m_value; ushort m_char; }; - double m_imaginaryPart; + double m_imaginaryPart = 0.; enum ValueFormat m_format; }; diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/variables.cpp analitza-19.12.3+p20.04+git20200418.1007/analitza/variables.cpp --- analitza-19.12.3+p20.04+git20200305.1807/analitza/variables.cpp 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/variables.cpp 2020-04-18 10:07:59.000000000 +0000 @@ -90,3 +90,14 @@ { return Expression(value(name)->copy()); } + +QString Variables::toString() const +{ + QString dbg; + dbg += QStringLiteral("Variables("); + for (Variables::const_iterator it = constBegin(), itEnd = constEnd(); it != itEnd; ++it) + dbg += it.key() + QLatin1Char('=') + it.value()->toString() + QLatin1String(", "); + dbg += QLatin1String(")"); + + return dbg; +} diff -Nru analitza-19.12.3+p20.04+git20200305.1807/analitza/variables.h analitza-19.12.3+p20.04+git20200418.1007/analitza/variables.h --- analitza-19.12.3+p20.04+git20200305.1807/analitza/variables.h 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/analitza/variables.h 2020-04-18 10:07:59.000000000 +0000 @@ -87,7 +87,9 @@ /** @returns the expression contained by the @p name identifier. */ Expression valueExpression(const QString& name) const; + QString toString() const; }; } + #endif diff -Nru analitza-19.12.3+p20.04+git20200305.1807/CMakeLists.txt analitza-19.12.3+p20.04+git20200418.1007/CMakeLists.txt --- analitza-19.12.3+p20.04+git20200305.1807/CMakeLists.txt 2020-03-05 18:07:34.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/CMakeLists.txt 2020-04-18 10:07:59.000000000 +0000 @@ -39,10 +39,7 @@ remove_definitions(-DQT_NO_CAST_FROM_ASCII) remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) -if (EXISTS "${CMAKE_SOURCE_DIR}/.git") - add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) - add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x060000) -endif() + add_subdirectory(analitza) add_subdirectory(analitzaplot) diff -Nru analitza-19.12.3+p20.04+git20200305.1807/debian/changelog analitza-19.12.3+p20.04+git20200418.1007/debian/changelog --- analitza-19.12.3+p20.04+git20200305.1807/debian/changelog 2020-03-05 18:07:38.000000000 +0000 +++ analitza-19.12.3+p20.04+git20200418.1007/debian/changelog 2020-04-18 10:08:00.000000000 +0000 @@ -1,8 +1,14 @@ -analitza (4:19.12.3+p20.04+git20200305.1807-0) focal; urgency=high +analitza (4:19.12.3+p20.04+git20200418.1007-0) focal; urgency=high * Automatic Ubuntu CI Build - -- Kubuntu CI Thu, 05 Mar 2020 18:07:38 +0000 + -- Kubuntu CI Sat, 18 Apr 2020 10:08:00 +0000 + +analitza (4:19.12.3-0ubuntu2) focal; urgency=medium + + * No-change rebuild against qtdeclarative-abi-5-12-8. + + -- Rik Mills Fri, 10 Apr 2020 20:10:08 +0100 analitza (4:19.12.3-0ubuntu1) focal; urgency=medium