From f36f76760acab291692f1c2aa15b5bf7ebc35d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 21 May 2012 18:34:10 +0200 Subject: [PATCH] Fix bug where the nth derivative of 0^n evaluated to 0 instead of n! (complement to commit cd0bc28e) --- mex/sources/bytecode/ErrorHandling.hh | 2 +- mex/sources/bytecode/Interpreter.cc | 2 +- preprocessor/DataTree.cc | 2 +- preprocessor/ExprNode.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh index a27e5fe44..a6bc1acae 100644 --- a/mex/sources/bytecode/ErrorHandling.hh +++ b/mex/sources/bytecode/ErrorHandling.hh @@ -1253,7 +1253,7 @@ public: int derivOrder = nearbyint(Stackf.top()); Stackf.pop(); if (fabs(v1f) < NEAR_ZERO && v2f > 0 - && derivOrder >= v2f + && derivOrder > v2f && fabs(v2f-nearbyint(v2f)) < NEAR_ZERO) { r = 0.0; diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc index a75943b5a..8adf84491 100644 --- a/mex/sources/bytecode/Interpreter.cc +++ b/mex/sources/bytecode/Interpreter.cc @@ -890,7 +890,7 @@ Interpreter::compute_block_time(int Per_u_, bool evaluate, int block_num, int si try { if (fabs(v1) < NEAR_ZERO && v2 > 0 - && derivOrder >= v2 + && derivOrder > v2 && fabs(v2-nearbyint(v2)) < NEAR_ZERO) Stack.push(0.0); else diff --git a/preprocessor/DataTree.cc b/preprocessor/DataTree.cc index 35c78c176..359470af6 100644 --- a/preprocessor/DataTree.cc +++ b/preprocessor/DataTree.cc @@ -685,7 +685,7 @@ DataTree::writePowerDeriv(ostream &output, bool use_dll) const << "#ifdef _MSC_VER" << endl << "# define nearbyint(x) (fabs((x)-floor(x)) < fabs((x)-ceil(x)) ? floor(x) : ceil(x))" << endl << "#endif" << endl - << " if ( fabs(x) < " << NEAR_ZERO << " && p > 0 && k >= p && fabs(p-nearbyint(p)) < " << NEAR_ZERO << " )" << endl + << " if ( fabs(x) < " << NEAR_ZERO << " && p > 0 && k > p && fabs(p-nearbyint(p)) < " << NEAR_ZERO << " )" << endl << " return 0.0;" << endl << " else" << endl << " {" << endl diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index 0a8a06a94..2e85db7af 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -2598,7 +2598,7 @@ BinaryOpNode::eval_opcode(double v1, BinaryOpcode op_code, double v2, int derivO return (pow(v1, v2)); case oPowerDeriv: if (fabs(v1) < NEAR_ZERO && v2 > 0 - && derivOrder >= v2 + && derivOrder > v2 && fabs(v2-nearbyint(v2)) < NEAR_ZERO) return 0.0; else