Commit 6bba30b9 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

PredicateSimple: %% instead of %

n%%m is a PredicateSimple yielding true
if m divides n, and false otherwise.

We can now use ASTs for PredicateSimple in the form

AST1 op AST2

where op belongs to {"==", "!=", "<=", ">=", ">", "<", "%%"};

and AST is anything that ExpressionCalculator can process, and
separated by pipes |

So, n%%m is equivalent (and a shorthand) for

%|n|m==0
parent bbb084f6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,6 +2,6 @@

namespace PsimagLite {
PredicateSimple::VectorStringType PredicateSimple::ops_ =
{"==", "!=", "<=", ">=", ">", "<", "%"};
{"==", "!=", "<=", ">=", ">", "<", "%%"};

}
+3 −1
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ public:
		lhs_ = pred.substr(0, location);
		op_ = pred.substr(location, length);
		rhs_ = pred.substr(location + length, n - location - length);
		if (lhs_ == "" || rhs_ == "")
			err("Left or right expression is empty\n");
	}

	template<typename T>
@@ -82,7 +84,7 @@ private:
			return (lv <= rv);
		if (op == ">=")
			return (lv >= rv);
		if (op == "%")
		if (op == "%%")
			return ((lv % rv) == 0);
		throw RuntimeError("Unknown operator " + op + "\n");
	}