From 2db21337966cc70d2718ffa82e04aab04e131ef5 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 4 Dec 2019 10:43:46 +0100 Subject: [PATCH] fix bugs with cbrt - it was not handled in the model block - output was incorrect for MATLAB/Octave and LaTeX --- src/DynareBison.yy | 2 ++ src/ExprNode.cc | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/DynareBison.yy b/src/DynareBison.yy index 36df7ca2..5734fa13 100644 --- a/src/DynareBison.yy +++ b/src/DynareBison.yy @@ -1014,6 +1014,8 @@ hand_side : '(' hand_side ')' { $$ = driver.add_atan($3); } | SQRT '(' hand_side ')' { $$ = driver.add_sqrt($3); } + | CBRT '(' hand_side ')' + { $$ = driver.add_cbrt($3); } | ABS '(' hand_side ')' { $$ = driver.add_abs($3); } | SIGN '(' hand_side ')' diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 9d116abd..0d473828 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -2777,7 +2777,22 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << "sqrt"; break; case UnaryOpcode::cbrt: - output << "cbrt"; + if (isMatlabOutput(output_type)) + { + output << "nthroot("; + arg->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); + output << ", 3)"; + return; + } + else if (isLatexOutput(output_type)) + { + output << R"(\sqrt[3]{)"; + arg->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); + output << "}"; + return; + } + else + output << "cbrt"; break; case UnaryOpcode::abs: output << "abs"; -- GitLab