]> granicus.if.org Git - icinga2/commitdiff
Implement some more utility functions
authorGunnar Beutner <gunnar@beutner.name>
Fri, 16 Jan 2015 09:35:20 +0000 (10:35 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Fri, 16 Jan 2015 09:35:20 +0000 (10:35 +0100)
refs #8169

lib/base/math-script.cpp
lib/base/value-operators.cpp

index a4deffaec3d3e80de2c4445e084c8ebe3944214c..7f2023f7b2b5f9833f69925147082f6e59b00f4f 100644 (file)
@@ -23,6 +23,7 @@
 #include "base/scriptframe.hpp"
 #include "base/initialize.hpp"
 #include <boost/math/special_functions/round.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
 #include <boost/foreach.hpp>
 #include <cmath>
 
@@ -138,6 +139,26 @@ static double MathTan(double x)
        return std::tan(x);
 }
 
+static bool MathIsnan(double x)
+{
+       return boost::math::isnan(x);
+}
+
+static bool MathIsinf(double x)
+{
+       return boost::math::isinf(x);
+}
+
+static double MathSign(double x)
+{
+       if (x > 0)
+               return 1;
+       else if (x < 0)
+               return -1;
+       else
+               return 0;
+}
+
 static void InitializeMathObj(void)
 {
        Dictionary::Ptr mathObj = new Dictionary();
@@ -171,6 +192,9 @@ static void InitializeMathObj(void)
        mathObj->Set("sin", new ScriptFunction(WrapScriptFunction(MathSin)));
        mathObj->Set("sqrt", new ScriptFunction(WrapScriptFunction(MathSqrt)));
        mathObj->Set("tan", new ScriptFunction(WrapScriptFunction(MathTan)));
+       mathObj->Set("isnan", new ScriptFunction(WrapScriptFunction(MathIsnan)));
+       mathObj->Set("isinf", new ScriptFunction(WrapScriptFunction(MathIsinf)));
+       mathObj->Set("sign", new ScriptFunction(WrapScriptFunction(MathSign)));
 
        ScriptGlobal::Set("Math", mathObj);
 }
index 51e998eb27c6eb3676b71d5f67beb8bc0aea80fe..56288233909bf5222800ab1709bdffaebf46c424 100644 (file)
@@ -554,7 +554,7 @@ bool icinga::operator<(const Value& lhs, const Value& rhs)
        if (lhs.IsString() && rhs.IsString())
                return static_cast<String>(lhs) < static_cast<String>(rhs);
        else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
-               return static_cast<int>(lhs) < static_cast<int>(rhs);
+               return static_cast<double>(lhs) < static_cast<double>(rhs);
        else if (lhs.GetTypeName() != rhs.GetTypeName())
                return lhs.GetTypeName() < rhs.GetTypeName();
        else
@@ -586,7 +586,7 @@ bool icinga::operator>(const Value& lhs, const Value& rhs)
        if (lhs.IsString() && rhs.IsString())
                return static_cast<String>(lhs) > static_cast<String>(rhs);
        else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
-               return static_cast<int>(lhs) > static_cast<int>(rhs);
+               return static_cast<double>(lhs) > static_cast<double>(rhs);
        else if (lhs.GetTypeName() != rhs.GetTypeName())
                return lhs.GetTypeName() > rhs.GetTypeName();
        else
@@ -618,7 +618,7 @@ bool icinga::operator<=(const Value& lhs, const Value& rhs)
        if (lhs.IsString() && rhs.IsString())
                return static_cast<String>(lhs) <= static_cast<String>(rhs);
        else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
-               return static_cast<int>(lhs) <= static_cast<int>(rhs);
+               return static_cast<double>(lhs) <= static_cast<double>(rhs);
        else if (lhs.GetTypeName() != rhs.GetTypeName())
                return lhs.GetTypeName() <= rhs.GetTypeName();
        else
@@ -650,7 +650,7 @@ bool icinga::operator>=(const Value& lhs, const Value& rhs)
        if (lhs.IsString() && rhs.IsString())
                return static_cast<String>(lhs) >= static_cast<String>(rhs);
        else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
-               return static_cast<int>(lhs) >= static_cast<int>(rhs);
+               return static_cast<double>(lhs) >= static_cast<double>(rhs);
        else if (lhs.GetTypeName() != rhs.GetTypeName())
                return lhs.GetTypeName() >= rhs.GetTypeName();
        else