[
https://issues.apache.org/jira/browse/MINIFICPP-367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16329617#comment-16329617
]
ASF GitHub Bot commented on MINIFICPP-367:
------------------------------------------
Github user phrocker commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/243#discussion_r162199080
--- Diff: extensions/expression-language/Expression.cpp ---
@@ -146,6 +149,124 @@ std::string expr_replaceEmpty(const
std::vector<std::string> &args) {
#endif // EXPRESSION_LANGUAGE_USE_REGEX
+std::string expr_binaryOp(const std::vector<std::string> &args,
+ long double (*ldop)(long double, long double),
+ int (*iop)(int, int),
+ bool long_only = false) {
+ try {
+ if (!long_only &&
+ args[0].find('.') == args[0].npos &&
+ args[1].find('.') == args[1].npos &&
+ args[1].find('e') == args[1].npos &&
+ args[0].find('e') == args[0].npos &&
+ args[0].find('E') == args[0].npos &&
+ args[1].find('E') == args[1].npos) {
+ return std::to_string(iop(std::stoi(args[0]), std::stoi(args[1])));
+ } else {
+ std::stringstream ss;
+ ss << std::fixed <<
std::setprecision(std::numeric_limits<double>::digits10)
+ << ldop(std::stold(args[0]), std::stold(args[1]));
+ auto result = ss.str();
+ result.erase(result.find_last_not_of('0') + 1, std::string::npos);
+
+ if (result.find('.') == result.length() - 1) {
+ result.erase(result.length() - 1, std::string::npos);
+ }
+
+ return result;
+ }
+ } catch (const std::exception &e) {
+ return "";
+ }
+}
+
+std::string expr_plus(const std::vector<std::string> &args) {
+ return expr_binaryOp(args,
+ [](long double a, long double b) { return a + b; },
--- End diff --
does it make sense to define these lambda's statically?
> Implement expression language arithmetic operations
> ---------------------------------------------------
>
> Key: MINIFICPP-367
> URL: https://issues.apache.org/jira/browse/MINIFICPP-367
> Project: NiFi MiNiFi C++
> Issue Type: Improvement
> Reporter: Andrew Christianson
> Assignee: Andrew Christianson
> Priority: Major
>
> Mathematical Operations and Numeric Manipulation
> plus
> minus
> multiply
> divide
> mod
> toRadix
> fromRadix
> random
> math
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)