Add some new Functions

This commit is contained in:
Justin Hammond 2014-07-20 00:30:15 +08:00
parent 2cf90d6ea5
commit ac1c9bf0a4
3 changed files with 36 additions and 0 deletions

View file

@ -74,6 +74,14 @@ namespace fl {
static scalar logicalAnd(scalar a, scalar b);
static scalar logicalOr(scalar a, scalar b);
static scalar negate(scalar a);
static scalar gt(scalar a, scalar b); //greater than
static scalar ge(scalar a, scalar b); //greater than or equal to
static scalar eq(scalar a, scalar b); //equal to
static scalar le(scalar a, scalar b); //less than or equal to
static scalar lt(scalar a, scalar b); //less than
static scalar logicalNot(scalar a);
static bool increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max);
static bool increment(std::vector<int>& x, int position, std::vector<int>& min, std::vector<int>& max);

View file

@ -110,6 +110,27 @@ namespace fl {
scalar Operation::negate(scalar a) {
return -a;
}
scalar Operation::gt(scalar a, scalar b) {
return isGt(a, b);
}
scalar Operation::ge(scalar a, scalar b) {
return isGE(a, b);
}
scalar Operation::eq(scalar a, scalar b) {
return isEq(a, b);
}
scalar Operation::le(scalar a, scalar b) {
return isLE(a, b);
}
scalar Operation::lt(scalar a, scalar b) {
return isLt(a, b);
}
scalar Operation::logicalNot(scalar a) {
return isEq(a, 1.0) ? 0.0 : 1.0; //Implementation in Operation.cpp
}
bool Operation::increment(std::vector<int>& x, std::vector<int>& min, std::vector<int>& max) {
return increment(x, (int) x.size() - 1, min, max);

View file

@ -227,6 +227,8 @@ namespace fl {
// (!) Logical and (~) Bitwise NOT
// this->_unaryOperators["!"] = new Operator("!", std::logical_not<scalar>, p, 1);
// ~ negates a number
this->operators["!"] = new Operator("!", fl::Op::logicalNot, p, 1);
this->operators["~"] = new Operator("~", fl::Op::negate, p, 1);
--p; //Power
this->operators["^"] = new Operator("^", std::pow, p, 1);
@ -280,6 +282,11 @@ namespace fl {
this->functions["pow"] = new BuiltInFunction("pow", &(std::pow));
this->functions["atan2"] = new BuiltInFunction("atan2", &(std::atan2));
this->functions["fmod"] = new BuiltInFunction("fmod", &(std::fmod));
this->functions["gt"] = new BuiltInFunction("gt", &(fl::Op::gt));
this->functions["lt"] = new BuiltInFunction("lt", &(fl::Op::lt));
this->functions["ge"] = new BuiltInFunction("ge", &(fl::Op::ge));
this->functions["le"] = new BuiltInFunction("le", &(fl::Op::le));
this->functions["eq"] = new BuiltInFunction("eq", &(fl::Op::eq));
}
std::string Function::space(const std::string& formula) const {