[dasher: 2/5] Robustness improvements to ExpansionPolicy code for finding-next-smallest double
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [dasher: 2/5] Robustness improvements to ExpansionPolicy code for finding-next-smallest double
- Date: Thu, 7 Jan 2010 14:20:41 +0000 (UTC)
commit 05f3660e3b6945003b106d48c43c93e5f2909461
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Sat Dec 19 21:01:21 2009 +0000
Robustness improvements to ExpansionPolicy code for finding-next-smallest double
Src/DasherCore/ExpansionPolicy.cpp | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/Src/DasherCore/ExpansionPolicy.cpp b/Src/DasherCore/ExpansionPolicy.cpp
index 62b8a1d..15e8ffc 100644
--- a/Src/DasherCore/ExpansionPolicy.cpp
+++ b/Src/DasherCore/ExpansionPolicy.cpp
@@ -22,10 +22,14 @@ BudgettingPolicy::BudgettingPolicy(unsigned int iNodeBudget) : m_iNodeBudget(iNo
double BudgettingPolicy::pushNode(CDasherNode *pNode, int iMin, int iMax, bool bExpand, double dParentCost) {
double dRes = getCost(pNode, iMin, iMax);
if (dRes >= dParentCost) {
- double eps = min(1.0, abs(dParentCost));
- while (dParentCost - (eps/2.0) < dParentCost) eps/=2.0;
- dRes = dParentCost - eps;
+ double eps = max(abs(dParentCost),1.0) * std::numeric_limits<double>::epsilon();
+ DASHER_ASSERT((dParentCost-eps) < dParentCost);
+ for (double nRes; (nRes = dParentCost - eps) < dParentCost; eps/=2.0) {
+ //nRes<dParentCost guaranteed true by loop test - remember it!
+ dRes = nRes;
+ }
}
+ DASHER_ASSERT(dRes < dParentCost);
vector<pair<double, CDasherNode*> > &target = (bExpand) ? sExpand : sCollapse;
target.push_back(pair<double, CDasherNode *>(dRes,pNode));
return dRes;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]