Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created October 26, 2016 02:21
Show Gist options
  • Select an option

  • Save toptensoftware/5da550148bb562f04dea9c12e2d8e8a2 to your computer and use it in GitHub Desktop.

Select an option

Save toptensoftware/5da550148bb562f04dea9c12e2d8e8a2 to your computer and use it in GitHub Desktop.
// NodeBinary for binary operations such as Add, Subtract etc...
class NodeBinary : Node
{
// Constructor accepts the two nodes to be operated on and function
// that performs the actual operation
public NodeBinary(Node lhs, Node rhs, Func<double, double, double> op)
{
_lhs = lhs;
_rhs = rhs;
_op = op;
}
Node _lhs; // Left hand side of the operation
Node _rhs; // Right hand side of the operation
Func<double, double, double> _op; // The callback operator
public override double Eval()
{
// Evaluate both sides
var lhsVal = _lhs.Eval();
var rhsVal = _rhs.Eval();
// Evaluate and return
var result = _op(lhsVal, rhsVal);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment