本文整理汇总了C++中Sine::eval方法的典型用法代码示例。如果您正苦于以下问题:C++ Sine::eval方法的具体用法?C++ Sine::eval怎么用?C++ Sine::eval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sine
的用法示例。
在下文中一共展示了Sine::eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evaluate_tree
// TODO: Expand to allow for more functions.
// TODO: When parsing e^(f(z)), use Exponential class instead of Power class.
// Evaluates the given expression tree on the given variable value.
ComplexNumber evaluate_tree(const ExpressionTreeNode *root, const ComplexNumber z) {
if (root->is_op_node()) {
ExpressionTreeBinaryOp *temp = (ExpressionTreeBinaryOp *) root;
ComplexNumber left = evaluate_tree(temp->get_left(), z);
ComplexNumber right = evaluate_tree(temp->get_right(), z);
// Find the appropriate operator, apply, then return.
if (temp->get_operator() == PLUS) {
return left + right;
} else if (temp->get_operator() == MINUS) {
return left - right;
} else if (temp->get_operator() == TIMES) {
return left * right;
} else if (temp->get_operator() == DIVIDE) {
return left / right;
} else { // temp->get_operator() == EXP
Power p (right);
return p.eval(left);
}
} else if (root->is_func_node()) {
ExpressionTreeFunction *temp = (ExpressionTreeFunction *) root;
ComplexNumber arg = evaluate_tree(temp->get_argument(), z);
// Find the appropriate function, evaluate, then return.
if (temp->get_function() == LOG) {
Logarithm l (1, 0);
return l.eval(arg);
} else if (temp->get_function() == SIN) {
Sine s (1, 1, 0);
return s.eval(arg);
} else if (temp->get_function() == COS) {
Cosine c (1, 1, 0);
return c.eval(arg);
} else { // temp->get_function() == TAN
Tangent t (1, 1, 0);
return t.eval(arg);
}
} else if (root->is_leaf_node()) {
ExpressionTreeLeaf *temp = (ExpressionTreeLeaf *) root;
return temp->get_val(); // Return the value itself
} else if (root->is_const_node()) {
ExpressionTreeConstant *temp = (ExpressionTreeConstant *) root;
// Return the corresponding mathematical constant
if (temp->get_constant() == e) {
return E;
} else if (temp->get_constant() == pi) {
return PI;
} else { // temp->get_constant() == phi
return PHI;
}
} else { // root->is_var_node()
return z;
}
}
示例2: eval
ComplexNumber Tangent::eval(const ComplexNumber z) const {
Sine sine (a, b, c);
Cosine cosine (a, b, c);
return sine.eval(z) / cosine.eval(z);
}