aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--die.h2
-rw-r--r--node/helpnode.cpp10
-rw-r--r--node/scalaroperatornode.cpp21
-rw-r--r--node/scalaroperatornode.h3
-rw-r--r--parsingtoolbox.cpp1
6 files changed, 28 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 731fa07..2899cb1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ project(diceparser)
add_subdirectory(irc)
add_subdirectory(cli)
-add_subdirectory(mobile)
+#add_subdirectory(mobile)
#add_subdirectory(webserver)
diff --git a/die.h b/die.h
index 10a6e8b..24b87cd 100644
--- a/die.h
+++ b/die.h
@@ -34,7 +34,7 @@ public:
/**
* @brief The ArithmeticOperator enum
*/
- enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION};
+ enum ArithmeticOperator {PLUS,MINUS,DIVIDE,MULTIPLICATION,POW};
/**
* @brief Die
*/
diff --git a/node/helpnode.cpp b/node/helpnode.cpp
index 1cefea8..25efdcd 100644
--- a/node/helpnode.cpp
+++ b/node/helpnode.cpp
@@ -37,6 +37,14 @@ void HelpNode::run(ExecutionNode* previous)
"Example (with ! as prefix):\n"
"!2d6\n"
"!1d20\n"
+ "!6d10e10k3 (L5R)\n"
+ "\n"
+ "Full documentation at: %1").arg(m_path));
+ /*txtResult->setText(QObject::tr("Rolisteam Dice Parser:\n"
+ "\n"
+ "Example (with ! as prefix):\n"
+ "!2d6\n"
+ "!1d20\n"
"\n"
"Operator list:\n"
"\n"
@@ -81,7 +89,7 @@ void HelpNode::run(ExecutionNode* previous)
"1d6+6 => roll one 6-sided die and add 6 to its result\n"
"(2d4+2)d10 => roll two 4-sided dice, add 2 to the result[2;8] then roll from four to ten 10-sided dice\n"
"\n"
- "Full documentation at: %1").arg(m_path));
+ "Full documentation at: %1").arg(m_path));*/
m_result->setPrevious(nullptr);
}
else if(nullptr != previous)
diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp
index 46c13c9..edc769d 100644
--- a/node/scalaroperatornode.cpp
+++ b/node/scalaroperatornode.cpp
@@ -81,7 +81,8 @@ void ScalarOperatorNode::run(ExecutionNode* previous)
case Die::DIVIDE:
m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal()));
break;
- default:
+ case Die::POW:
+ m_scalarResult->setValue(pow(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal()));
break;
}
@@ -111,24 +112,28 @@ void ScalarOperatorNode::setInternalNode(ExecutionNode* node)
}
qint64 ScalarOperatorNode::add(qreal a,qreal b)
{
- return a+b;
+ return static_cast<qint64>(a+b);
}
qint64 ScalarOperatorNode::substract(qreal a,qreal b)
{
- return a-b;
+ return static_cast<qint64>(a-b);
}
qreal ScalarOperatorNode::divide(qreal a,qreal b)
{
- if(b==0)
+ if(qFuzzyCompare(b,0))
{
m_errors.insert(DIVIDE_BY_ZERO,QObject::tr("Division by zero"));
return 0;
}
- return (qreal)a/b;
+ return static_cast<qreal>(a/b);
}
qint64 ScalarOperatorNode::multiple(qreal a,qreal b)
{
- return a*b;
+ return static_cast<qint64>(a*b);
+}
+qint64 ScalarOperatorNode::pow(qreal a,qreal b)
+{
+ return static_cast<qint64>(std::pow(a,b));
}
Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const
{
@@ -157,9 +162,9 @@ QString ScalarOperatorNode::toString(bool wl) const
case Die::DIVIDE:
op="/";
break;
- default:
+ case Die::POW:
+ op="^";
break;
-
}
if(wl)
{
diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h
index f17f99f..04c3c23 100644
--- a/node/scalaroperatornode.h
+++ b/node/scalaroperatornode.h
@@ -94,6 +94,7 @@ public:
* @return
*/
virtual ExecutionNode *getCopy() const;
+
private:
/**
* @brief add
@@ -116,6 +117,8 @@ private:
*/
static qint64 multiple(qreal,qreal);
+ static qint64 pow(qreal a, qreal b);
+
private:
ExecutionNode* m_internalNode;
ScalarResult* m_scalarResult;
diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp
index 63ae406..07ad01a 100644
--- a/parsingtoolbox.cpp
+++ b/parsingtoolbox.cpp
@@ -62,6 +62,7 @@ ParsingToolBox::ParsingToolBox()
m_arithmeticOperation->insert(QStringLiteral("x"),Die::MULTIPLICATION);
m_arithmeticOperation->insert(QStringLiteral("/"),Die::DIVIDE);
m_arithmeticOperation->insert(QStringLiteral("÷"),Die::DIVIDE);
+ m_arithmeticOperation->insert(QStringLiteral("^"),Die::POW);
}