summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorxinjiang <xinjiang@multicorewareinc.com>2013-12-31 15:08:49 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-12-31 17:37:00 -0600
commit9bbe7f7078b0c85523090437c3488e2254aa1bce (patch)
tree1d2f207e0ed7910dc009e4f76aba848fadccfef3 /sc
parent2263e435686f223bade8a0b5e05a9c60167a219a (diff)
GPU Calc: Fix accuracy not reach 11 in MDURATION
AMLOEXT-223 FIX Change-Id: Ic7f35d85cc10f14487411633a54c43bbfafe688f Signed-off-by: haochen <haochen@multicorewareinc.com> Signed-off-by: Wei Wei <weiwei@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com> Signed-off-by: Wei Wei <weiwei@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/op_financial.cxx67
-rw-r--r--sc/source/core/opencl/opinlinefun_finacial.cxx38
2 files changed, 82 insertions, 23 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index e13b86c4060a..2bd250e829bf 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -761,13 +761,15 @@ void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss,
void OpMDuration::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
- decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
+ decls.insert(GetDuration_newDecl);decls.insert(lcl_Getcoupnum_newDecl);
+ decls.insert(addMonthsDecl);decls.insert(checklessthanDecl);
+ decls.insert(setDayDecl);decls.insert(ScaDateDecl);
decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
- decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
- funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
+ funs.insert(GetDuration_new);funs.insert(lcl_Getcoupnum_new);
+ funs.insert(addMonths);funs.insert(checklessthan);
+ funs.insert(setDay);funs.insert(ScaDate);
funs.insert(GetYearFrac);funs.insert(DaysToDate);
- funs.insert(GetNullDate);funs.insert(DateToDays);
funs.insert(DaysInMonth);funs.insert(IsLeapYear);
}
@@ -791,31 +793,50 @@ void OpMDuration::GenSlidingWindowFunction(std::stringstream& ss,
ss << " double arg3 = " << GetBottom() << ";\n";
ss << " double arg4 = " << GetBottom() << ";\n";
ss << " double arg5 = " << GetBottom() << ";\n";
- unsigned j = vSubArguments.size();
- while (j--)
- {
- FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
assert(pCur);
- if(pCur->GetType() == formula::svSingleVectorRef)
- {
+ if (pCur->GetType() == formula::svSingleVectorRef)
+ {
#ifdef ISNAN
const formula::SingleVectorRefToken* pSVR =
- dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
- ss << " if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
- ss << vSubArguments[j]->GenSlidingWindowDeclRef();
- ss << "))\n";
- ss << " arg" << j << " = " <<GetBottom() << ";\n";
- ss << " else\n";
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+ ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
#endif
- ss << " arg" << j << " = ";
- ss << vSubArguments[j]->GenSlidingWindowDeclRef();
- ss << ";\n";
- }
}
- ss << " int nNullDate = GetNullDate();\n";
- ss << " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
+ else if (pCur->GetType() == formula::svDouble)
+ {
+#ifdef ISNAN
+ ss << " {\n";
+#endif
+ }
+#ifdef ISNAN
+ if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+ {
+ ss << " if (isNan(";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << "))\n";
+ ss << " arg" << i << " = 0;\n";
+ ss << " else\n";
+ ss << " arg" << i << " = ";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+ ss << " }\n";
+ }
+ else
+ {
+ ss << " arg" << i << " = ";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+ }
+#else
+ ss << " arg" << i;
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+ }
+ ss << " int nNullDate = 693594;\n";
+ ss << " tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
ss << " arg3, (int)arg4, (int)arg5);\n";
- ss << " tmp /= 1.0 + arg3 / (int)arg4;\n";
+ ss << " tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
ss << " return tmp;\n";
ss << "}";
}
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 91d04d2e9490..154a9f5eebff 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -1428,6 +1428,44 @@ std::string GetDuration=
" fDur /= nFreq;\n"
" return fDur;\n""}\n";
+std::string GetDuration_newDecl=
+"double GetDuration_new( \n"
+" int nNullDate, int nSettle, int nMat, double fCoup,\n"
+" double fYield, int nFreq, int nBase );\n";
+
+std::string GetDuration_new=
+"double GetDuration_new( \n"
+" int nNullDate, int nSettle, int nMat, double fCoup,\n"
+" double fYield, int nFreq, int nBase )\n"
+" {\n"
+" double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
+" double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
+"nFreq,nBase);\n"
+" double fDur = 0.0;\n"
+" fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
+" fYield = fYield * pow(nFreq, -1.0);\n"
+" fYield += 1.0;\n"
+" double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
+" int t;\n"
+" double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
+" for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+" tmp0 = (t + nDiff) * ( fCoup ) ;\n"
+" tmp1 = pow( fYield, t + nDiff ) ;\n"
+" tmp2 = tmp0 * pow(tmp1, -1);\n"
+" fDur += tmp2;\n"
+" }\n"
+" fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
+" fNumOfCoups + nDiff ),-1);\n"
+" double p = 0.0;\n"
+" for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+" tmp0 = pow( fYield, t + nDiff );\n"
+" p += fCoup * pow(tmp0, -1);}\n"
+" p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
+" fDur = fDur * pow(p, -1.0);\n"
+" fDur = fDur * pow(nFreq, -1.0);\n"
+" return fDur;\n"
+" }\n";
+
std::string ScGetGDADecl=
"double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
"double fFaktor);\n";