aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2018-09-02 12:22:03 +0200
committerRenaud G <renaud@rolisteam.org>2018-09-02 12:22:19 +0200
commit49567f95bf6985707fcf8c2836c761ce39602636 (patch)
tree8c57132da55d15f14d7f604a61396d266afff00a /node
parente5a37ca38ef7b28695313e4b59f62c03d4801f2d (diff)
downloadOneRoll-49567f95bf6985707fcf8c2836c761ce39602636.tar.gz
OneRoll-49567f95bf6985707fcf8c2836c761ce39602636.zip
Adding pow
Diffstat (limited to 'node')
-rw-r--r--node/helpnode.cpp10
-rw-r--r--node/scalaroperatornode.cpp21
-rw-r--r--node/scalaroperatornode.h3
3 files changed, 25 insertions, 9 deletions
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;