Commit 129d404e authored by Ferhat Mihoubi's avatar Ferhat Mihoubi

- The binary operator oDerivPower is implemented in bytecode

parent d8dbc68e
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "CodeInterpreter.hh" #include "CodeInterpreter.hh"
#ifdef DEBUG_EX
# include <math>
# include "mex_interface.hh"
#endif
using namespace std; using namespace std;
...@@ -1078,6 +1082,33 @@ print_expression(it_code_type it_code, bool evaluate, int size, int block_num, b ...@@ -1078,6 +1082,33 @@ print_expression(it_code_type it_code, bool evaluate, int size, int block_num, b
Stack.push(tmp_out.str()); Stack.push(tmp_out.str());
#ifdef DEBUG #ifdef DEBUG
mexPrintf("ok\n"); mexPrintf("ok\n");
#endif
break;
case oPowerDeriv:
{
int derivOrder = nearbyint(Stackf.top());
Stackf.pop();
if (fabs(v1f) < NEAR_ZERO && v2f > 0 &&
derivOrder >= v2f &&
fabs(v2f-nearbyint(v2f)) < NEAR_ZERO)
Stackf.push(0.0);
else
{
double dxp = pow(v1f, v2f-derivOrder);
for (int i=0; i<derivOrder; i++)
dxp *= v2f--;
Stackf.push(dxp);
}
tmp_out.str("");
if(isnan(r))
tmp_out << "$ PowerDeriv ";
else
tmp_out << "PowerDeriv";
tmp_out << "(" << v1 << ", " << v2 << ", " << derivOrder << ")";
Stack.push(tmp_out.str());
}
#ifdef DEBUG
tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << ")|";
#endif #endif
break; break;
case oMax: case oMax:
......
...@@ -874,6 +874,35 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si ...@@ -874,6 +874,35 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si
tmp_out << " |" << v1 << "^" << v2 << "|"; tmp_out << " |" << v1 << "^" << v2 << "|";
#endif #endif
break; break;
case oPowerDeriv:
{
int derivOrder = nearbyint(Stack.top());
Stack.pop();
try
{
if (fabs(v1) < NEAR_ZERO && v2 > 0 &&
derivOrder >= v2 &&
fabs(v2-nearbyint(v2)) < NEAR_ZERO)
Stack.push(0.0);
else
{
double dxp = pow1(v1, v2-derivOrder);
for (int i=0; i<derivOrder; i++)
dxp *= v2--;
Stack.push(dxp);
}
}
catch(FloatingPointExceptionHandling &fpeh)
{
mexPrintf("%s %s\n",fpeh.GetErrorMsg().c_str(),error_location(evaluate, steady_state, size, block_num, it_, Per_u_).c_str());
go_on = false;
}
}
#ifdef DEBUG
tmp_out << " |PowerDeriv(" << v1 << ", " << v2 << ")|";
#endif
break;
case oMax: case oMax:
Stack.push(max(v1, v2)); Stack.push(max(v1, v2));
#ifdef DEBUG #ifdef DEBUG
...@@ -2429,7 +2458,11 @@ Interpreter::compute_blocks(string file_name, string bin_basename, bool steady_s ...@@ -2429,7 +2458,11 @@ Interpreter::compute_blocks(string file_name, string bin_basename, bool steady_s
delete fb; delete fb;
} }
if (block >= 0) if (block >= 0)
go_on = false; {
go_on = false;
}
break; break;
case FEND: case FEND:
#ifdef DEBUG #ifdef DEBUG
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include <stdint.h> #include <stdint.h>
#define NEAR_ZERO (1e-12)
using namespace std; using namespace std;
/** /**
......
...@@ -2525,6 +2525,11 @@ BinaryOpNode::compile(ostream &CompileCode, unsigned int &instruction_number, ...@@ -2525,6 +2525,11 @@ BinaryOpNode::compile(ostream &CompileCode, unsigned int &instruction_number,
} }
return; return;
} }
if (op_code == oPowerDeriv)
{
FLDC_ fldc(powerDerivOrder);
fldc.write(CompileCode, instruction_number);
}
arg1->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic, tef_terms); arg1->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic, tef_terms);
arg2->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic, tef_terms); arg2->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx, dynamic, steady_dynamic, tef_terms);
FBINARY_ fbinary(op_code); FBINARY_ fbinary(op_code);
......
...@@ -107,7 +107,6 @@ enum ExprNodeOutputType ...@@ -107,7 +107,6 @@ enum ExprNodeOutputType
#define MIN_COST_C (40*4) #define MIN_COST_C (40*4)
#define MIN_COST(is_matlab) ((is_matlab) ? MIN_COST_MATLAB : MIN_COST_C) #define MIN_COST(is_matlab) ((is_matlab) ? MIN_COST_MATLAB : MIN_COST_C)
#define NEAR_ZERO (1e-12)
//! Base class for expression nodes //! Base class for expression nodes
class ExprNode class ExprNode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment