diff --git a/src/basic.cpp b/src/basic.cpp index f2d4774961d523d4589d085fa720d925b61cb652..6b7a408de8aa686d643269ba61bc03d152c215dc 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -633,7 +633,7 @@ string mpfrCodeGenerator(const ast_ptr &expr, size_t &mpfr_variables, const std: auto it = map.find(callee); call_str = it->second; string callee_str; - if (call_str == "mpfr_pow") { + if (call_str == "mpfr_pow" || call_str == "mpfr_atan2") { string str1 = argsStr.at(0), str2 = argsStr.at(1); callee_str = call_str + "(mp" + to_string(mpfr_variables) + ", " + str1 + ", " + str2 + ", MPFR_RNDN);"; } else if (call_str == "mpfr_fma") { diff --git a/src/geneCode.cpp b/src/geneCode.cpp index 98c26061ae2745ac842615cbb9d4877ebc6db942..ab5f001c8289d85811c4ee2eb3fca463c719552d 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -318,6 +318,7 @@ string geneMpfrCode(const ast_ptr &exprAst, const string uniqueLabel, vector interval = exprInfoVector.at(i).intervals; - - string &exprStr = exprInfoVector.at(i).exprStr; - // generate if statement - if (i == 0) - { - fout << " if("; - } - else - { - fout << " } else if("; - } - for(size_t j = 0; j < interval.size(); j +=2) + fout << " result = " << exprStr << ";" << "\n"; + fout << " return result;" << "\n"; + fout << "}" << "\n"; + } + else + { + for (size_t i = 0; i < exprInfoVector.size(); i++) { - if(j < interval.size() - 2) + std::vector interval = exprInfoVector.at(i).intervals; + + string &exprStr = exprInfoVector.at(i).exprStr; + // generate if statement + if (i == 0) { - fout << "(" << interval.at(j) << " < " << vars.at(j / 2) << " && " << vars.at(j / 2) << " < " << interval.at(j + 1) << ") && "; + fout << " if("; } else { - fout << "(" << interval.at(j) << " < " << vars.at(j / 2) << " && " << vars.at(j / 2) << " < " << interval.at(j + 1) << ")"; + fout << " } else if("; + } + for(size_t j = 0; j < interval.size(); j +=2) + { + if(j < interval.size() - 2) + { + fout << "(" << interval.at(j) << " < " << vars.at(j / 2) << " && " << vars.at(j / 2) << " < " << interval.at(j + 1) << ") && "; + } + else + { + fout << "(" << interval.at(j) << " < " << vars.at(j / 2) << " && " << vars.at(j / 2) << " < " << interval.at(j + 1) << ")"; + } } + fout << ") {" << "\n"; + fout << " result = " << exprStr << ";" << "\n"; } - fout << ") {" << "\n"; + fout << " } else {" << "\n"; fout << " result = " << exprStr << ";" << "\n"; + fout << " }" << "\n"; + fout << " return result;" << "\n"; + fout << "}" << "\n"; } - fout << " } else {" << "\n"; - fout << " result = " << exprStr << ";" << "\n"; - fout << " }" << "\n"; - fout << " return result;" << "\n"; - fout << "}" << "\n"; fout << std::flush; fout.close();