From fd13c0340105072f21c901dfb4247ef4740b7368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 23 Jun 2020 15:59:35 +0200 Subject: [PATCH] use_dll: use fmax() and fmin() from C99 to compute max and min operators --- src/DynamicModel.cc | 6 ------ src/ExprNode.cc | 10 ++++++++-- src/StaticModel.cc | 6 ------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index db45cf67..f64b7c9f 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -623,9 +623,6 @@ DynamicModel::writeDynamicPerBlockCFiles(const string &basename) const << "#include <stdlib.h>" << endl << "#include <stdbool.h>" << endl << R"(#include "mex.h")" << endl - << endl - << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl - << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl << endl; // Write function definition if BinaryOpcode::powerDeriv is used @@ -1436,9 +1433,6 @@ DynamicModel::writeDynamicCFile(const string &basename) const << "#include <math.h>" << endl << "#include <stdlib.h>" << endl << R"(#include "mex.h")" << endl - << endl - << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl - << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl << endl; // Write function definition if BinaryOpcode::powerDeriv is used diff --git a/src/ExprNode.cc b/src/ExprNode.cc index c9310a37..4d0ef751 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -4472,10 +4472,16 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << "pow("; break; case BinaryOpcode::max: - output << "max("; + if (isCOutput(output_type)) + output << "fmax("; + else + output << "max("; break; case BinaryOpcode::min: - output << "min("; + if (isCOutput(output_type)) + output << "fmin("; + else + output << "min("; break; default: ; diff --git a/src/StaticModel.cc b/src/StaticModel.cc index 1fad42f9..2afc481d 100644 --- a/src/StaticModel.cc +++ b/src/StaticModel.cc @@ -307,9 +307,6 @@ StaticModel::writeStaticPerBlockCFiles(const string &basename) const << "#include <math.h>" << endl << "#include <stdlib.h>" << endl << R"(#include "mex.h")" << endl - << endl - << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl - << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl << endl; // Write function definition if BinaryOpcode::powerDeriv is used @@ -1695,9 +1692,6 @@ StaticModel::writeStaticCFile(const string &basename) const << "#include <math.h>" << endl << "#include <stdlib.h>" << endl << R"(#include "mex.h")" << endl - << endl - << "#define max(a, b) (((a) > (b)) ? (a) : (b))" << endl - << "#define min(a, b) (((a) > (b)) ? (b) : (a))" << endl << endl; // Write function definition if BinaryOpcode::powerDeriv is used -- GitLab