[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - sc/source

yiming ju yiming at multicorewareinc.com
Fri Nov 1 20:16:46 CET 2013


 sc/source/core/opencl/opinlinefun_finacial.cxx |  941 +++++++++++++------------
 1 file changed, 490 insertions(+), 451 deletions(-)

New commits:
commit 63798515b249dabd4af0ca4fd913536398f739ff
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Fri Nov 1 17:48:31 2013 +0800

    GPU Calc: refactor string formatting in some GPU inline functions
    
    Change-Id: I4ceb86ca84854a4e14c0720d6216d4c658a97859
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 05e6a5f..27a1625 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -14,10 +14,10 @@ std::string approxEqual =
 "bool approxEqual(double a, double b)\n"
 "{\n"
 "     if (a == b)\n"
-        "\t\treturn true;\n"
-    "\tdouble x = a - b;\n"
-    "\treturn (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
-    "16777216.0)));\n"
+"        return true;\n"
+"     double x = a - b;\n"
+"     return (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
+"16777216.0)));\n"
 "}\n";
 
 std::string nKorrValDecl ="double constant nKorrVal[]"
@@ -32,21 +32,22 @@ std::string RoundDecl = "double  Round(double fValue);\n";
 std::string Round =
 "double  Round(double fValue)\n"
 "{\n"
-    "\tif (fValue == 0.0)\n"
-    "\t\treturn fValue;\n"
-    "\tdouble fFac = 0;\n"
-    "\tint nExp;\n"
-    "\tif (fValue > 0.0)\n"
-        "\t\tnExp = (floor(log10(fValue)));\n"
-    "\telse\n"
-    "\t\tnExp = 0;\n"
-    "\tint nIndex = 15 - nExp;\n"
-    "\tif (nIndex > 15)\n"
-        "\t\tnIndex = 15;\n"
-    "\telse if (nIndex <= 1)\n"
-        "\t\tnIndex = 0;\n"
-    "\tfValue = floor(fValue + 0.5 + nKorrVal[nIndex]);\n"
-    "\treturn fValue;\n"
+"    if ( fValue == 0.0  )\n"
+"        return fValue;\n"
+"\n"
+"    double fFac = 0;\n"
+"    int nExp;\n"
+"    if ( fValue > 0.0 )\n"
+"        nExp = ( floor( log10( fValue ) ) );\n"
+"    else\n"
+"        nExp = 0;\n"
+"    int nIndex = 15 - nExp;\n"
+"    if ( nIndex > 15 )\n"
+"        nIndex = 15;\n"
+"    else if ( nIndex <= 1 )\n"
+"        nIndex = 0;\n"
+"    fValue = floor( fValue + 0.5 + nKorrVal[nIndex] );\n"
+"    return fValue;\n"
 "}\n";
 
 std::string GetRmzDecl =
@@ -55,27 +56,29 @@ std::string GetRmzDecl =
 std::string GetRmz=
 "double GetRmz( double fZins, double fZzr, double fBw, double fZw, int nF )\n"
 "{\n"
-    "\tdouble      fRmz;\n"
-    "\tif( fZins == 0.0 )\n"
-        "\t\tfRmz = ( fBw + fZw ) / fZzr;\n"
-    "\telse\n"
-        "\t\t{\n"
-            "\t\t\tdouble  fTerm = pow( 1.0 + fZins, fZzr );\n"
-            "\t\t\tif( nF > 0 )\n"
-                      "\t\t\t\tfRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw"
-                      " * fZins / ( 1.0 - 1.0 / fTerm ) ) / ( 1.0 + fZins );\n"
-            "\t\t\telse\n"
-            "\t\t\t\tfRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins /"
-            "( 1.0 - 1.0 / fTerm );\n"
-        "\t\t}\n"
-    "\treturn -fRmz;\n"
-"}\n\n";
+"    double      fRmz;\n"
+"    if( fZins == 0.0 )\n"
+"        fRmz = ( fBw + fZw ) / fZzr;\n"
+"    else\n"
+"    {\n"
+"        double  fTerm = pow( 1.0 + fZins, fZzr );\n"
+"        if( nF > 0 )\n"
+"            fRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1."
+"0 / fTerm ) ) / ( 1.0 + fZins );\n"
+"        else\n"
+"            fRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins /( 1.0 - 1.0 "
+"/ fTerm );\n"
+"    }\n"
+"    return -fRmz;\n"
+"}\n";
 
 std::string GetZwDecl =
-"double GetZw( double fZins, double fZzr, double fRmz, double fBw, int nF );\n";
+"double GetZw( double fZins, double fZzr, double fRmz,"
+"double fBw, int nF );\n";
 
 std::string GetZw =
-"double GetZw( double fZins, double fZzr, double fRmz, double fBw, int nF )\n"
+"double GetZw( double fZins, double fZzr, double fRmz,"
+"double fBw, int nF )\n"
 "{\n"
 "    double      fZw;\n"
 "    if( fZins == 0.0 )\n"
@@ -84,13 +87,13 @@ std::string GetZw =
 "    {\n"
 "        double  fTerm = pow( 1.0 + fZins, fZzr );\n"
 "        if( nF > 0 )\n"
-"            fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *"
-"( fTerm - 1.0 ) / fZins;\n"
+"                fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
+"/ fZins;\n"
 "        else\n"
-"            fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;\n"
+"                fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;\n"
 "    }\n"
 "    return -fZw;\n"
-"}\n\n";
+"}\n";
 
 std::string IsLeapYearDecl =
 "bool IsLeapYear( int n );\n";
@@ -98,7 +101,8 @@ std::string IsLeapYearDecl =
 std::string IsLeapYear =
 "bool IsLeapYear( int n )\n"
 "{\n"
-    "return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == 0 ) );\n"
+"    return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == "
+"0 ) );\n"
 "}\n";
 
 std::string DaysInMonthDecl=
@@ -107,8 +111,8 @@ std::string DaysInMonthDecl=
 std::string DaysInMonth =
 "int DaysInMonth( int nMonth, int nYear )\n"
 "{\n"
- "   int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
- "                                       31, 31, 30, 31, 30, 31 };\n"
+"    int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
+"                31, 31, 30, 31, 30, 31 };\n"
 "\n"
 "    if ( nMonth != 2 )\n"
 "        return aDaysInMonth[nMonth-1];\n"
@@ -137,7 +141,8 @@ std::string DaysToDate =
 "        nTempDays = nDays;\n"
 "        *rYear = (int)((nTempDays / 365) - i);\n"
 "        nTempDays -= ((int) *rYear -1) * 365;\n"
-"        nTempDays -= (( *rYear -1) / 4) - (( *rYear -1) / 100) + ((*rYear -1) / 400);\n"
+"        nTempDays -= (( *rYear -1) / 4) - (( *rYear -1) / 100) +"
+"((*rYear -1) / 400);\n"
 "        bCalc = false;\n"
 "        if ( nTempDays < 1 )\n"
 "        {\n"
@@ -175,7 +180,6 @@ std::string DateToDays=
 "{\n"
 "    int nDays = ((int)nYear-1) * 365;\n"
 "    nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);\n"
-
 "    for( int i = 1; i < nMonth; i++ )\n"
 "        nDays += DaysInMonth(i,nYear);\n"
 "    nDays += nDay;\n"
@@ -183,13 +187,14 @@ std::string DateToDays=
 "    return nDays;\n"
 "}\n";
 
+
 std::string GetNullDateDecl=
 "int GetNullDate();\n";
 
 std::string GetNullDate=
 "int GetNullDate()\n"
 "{\n"
-"     return DateToDays(30,12,1899 );\n"
+"    return DateToDays(30,12,1899 );\n"
 "}\n";
 
 std::string ScaDateDecl=
@@ -202,22 +207,22 @@ std::string ScaDate=
 "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
 "int *b30Days,int *bUSMode,int *nDay)\n"
 "{\n"
-"DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
-"*bLastDayMode = (nBase != 5);\n"
-"*bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
-"*b30Days = (nBase == 0) || (nBase == 4);\n"
-"*bUSMode = (nBase == 0);\n"
-    "if( *b30Days)\n"
-    "{\n"
-        "*nDay = min( *nOrigDay, 30);\n"
-        "if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
-        "*nDay = 30;\n"
-    "}\n"
-    "else\n"
-    "{\n"
-        "int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
-        "*nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
-    "}\n"
+"    DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
+"    *bLastDayMode = (nBase != 5);\n"
+"    *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
+"    *b30Days = (nBase == 0) || (nBase == 4);\n"
+"    *bUSMode = (nBase == 0);\n"
+"    if( *b30Days)\n"
+"    {\n"
+"        *nDay = min( *nOrigDay, 30);\n"
+"        if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
+"        *nDay = 30;\n"
+"    }\n"
+"    else\n"
+"    {\n"
+"        int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
+"        *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
+"    }\n"
 "}\n";
 
 std::string addMonthsDecl=
@@ -228,31 +233,31 @@ std::string addMonths=
 "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
 "int *nMonth,int nMonthCount,int *year)\n"
 "{\n"
-    "int nNewMonth = nMonthCount + *nMonth;\n"
-    "if( nNewMonth > 12 )\n"
-    "{\n"
-        "--nNewMonth;\n"
-        "*year+=nNewMonth / 12 ;\n"
-        "*nMonth = ( nNewMonth % 12 ) + 1;\n"
-    "}\n"
-    "else if( nNewMonth < 1 )\n"
-    "{\n"
-        "*year+= nNewMonth / 12 - 1 ;\n"
-        "*nMonth =  nNewMonth % 12 + 12 ;\n"
-    "}\n"
-    "else\n"
-    "*nMonth = nNewMonth ;\n"
-    "if( b30Days )\n"
-    "{\n"
-        "*nDay = min( nOrigDay, 30);\n"
-        "if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
-            "*nDay = 30;\n"
-    "}\n"
-    "else\n"
-    "{\n"
-        "int nLastDay = DaysInMonth( *nMonth, *year );\n"
-        "*nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
-    "}\n"
+"    int nNewMonth = nMonthCount + *nMonth;\n"
+"    if( nNewMonth > 12 )\n"
+"    {\n"
+"        --nNewMonth;\n"
+"        *year+=nNewMonth / 12 ;\n"
+"        *nMonth = ( nNewMonth % 12 ) + 1;\n"
+"    }\n"
+"    else if( nNewMonth < 1 )\n"
+"    {\n"
+"        *year+= nNewMonth / 12 - 1 ;\n"
+"        *nMonth =  nNewMonth % 12 + 12 ;\n"
+"    }\n"
+"    else\n"
+"        *nMonth = nNewMonth ;\n"
+"    if( b30Days )\n"
+"    {\n"
+"        *nDay = min( nOrigDay, 30);\n"
+"        if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
+"            *nDay = 30;\n"
+"    }\n"
+"    else\n"
+"    {\n"
+"        int nLastDay = DaysInMonth( *nMonth, *year );\n"
+"        *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
+"    }\n"
 "}\n";
 
 std::string getDaysInMonthRangeDecl=
@@ -261,17 +266,17 @@ std::string getDaysInMonthRangeDecl=
 std::string getDaysInMonthRange=
 "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
 "{\n"
-    "if( nFrom > nTo )\n"
-        "return 0;\n"
-    "int nRet = 0;\n"
-    "if( b30Days )\n"
-        "nRet = (nTo - nFrom + 1) * 30;\n"
-    "else\n"
-    "{\n"
-        "for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
-            "nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
-    "}\n"
-    "return nRet;\n"
+"    if( nFrom > nTo )\n"
+"        return 0;\n"
+"    int nRet = 0;\n"
+"    if( b30Days )\n"
+"        nRet = (nTo - nFrom + 1) * 30;\n"
+"    else\n"
+"    {\n"
+"        for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
+"            nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
+"    }\n"
+"    return nRet;\n"
 "}\n";
 
 std::string GetDaysInYearsDecl=
@@ -280,18 +285,18 @@ std::string GetDaysInYearsDecl=
 std::string GetDaysInYears=
 "int GetDaysInYears( int nYear1, int nYear2 )\n"
 "{\n"
-    "int  nLeaps = 0;\n"
-    "for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
-    "{\n"
-        "if( IsLeapYear( n ) )\n"
-            "nLeaps++;\n"
-    "}\n"
-    "int  nSum = 1;\n"
-    "nSum += nYear2;\n"
-    "nSum -= nYear1;\n"
-    "nSum *= 365;\n"
-    "nSum += nLeaps;\n"
-    "return nSum;\n"
+"    int  nLeaps = 0;\n"
+"    for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
+"    {\n"
+"        if( IsLeapYear( n ) )\n"
+"            nLeaps++;\n"
+"    }\n"
+"    int  nSum = 1;\n"
+"    nSum += nYear2;\n"
+"    nSum -= nYear1;\n"
+"    nSum *= 365;\n"
+"    nSum += nLeaps;\n"
+"    return nSum;\n"
 "}\n";
 
 std::string GetDaysInYearDecl=
@@ -300,22 +305,22 @@ std::string GetDaysInYearDecl=
 std::string GetDaysInYear=
 "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
 "{\n"
-"switch( nMode )\n"
-"{\n"
-"case 0:\n"
-"case 2:\n"
-"case 4:\n"
-     "return 360;\n"
-"case 1:\n"
-     "{\n"
-      "int  nD=0, nM=0, nY=0;\n"
-        "nDate += nNullDate;\n"
-        "DaysToDate( nDate, &nD, &nM, &nY );\n"
-        "return IsLeapYear( nY )? 366 : 365;\n"
-    "}\n"
-"case 3:\n"
-    "return 365;\n"
-"}\n"
+"    switch( nMode )\n"
+"    {\n"
+"    case 0:\n"
+"    case 2:\n"
+"    case 4:\n"
+"        return 360;\n"
+"    case 1:\n"
+"        {\n"
+"            int  nD=0, nM=0, nY=0;\n"
+"            nDate += nNullDate;\n"
+"            DaysToDate( nDate, &nD, &nM, &nY );\n"
+"            return IsLeapYear( nY )? 366 : 365;\n"
+"        }\n"
+"    case 3:\n"
+"        return 365;\n"
+"    }\n"
 "}\n";
 
 std::string getDaysInYearRangeDecl =
@@ -324,70 +329,75 @@ std::string getDaysInYearRangeDecl =
 std::string getDaysInYearRange=
 "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
 "{\n"
-    "if( nFrom > nTo )\n"
-        "return 0;\n"
-    "return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo );\n"
+"    if( nFrom > nTo )\n"
+"        return 0;\n"
+"    return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
+";\n"
 "}\n";
 
 
 std::string getDiffDecl=
-"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,int fbLastDay,"
-"int fb30Days,int fbUSMode,int fnDay,""int tDay,int tMonth,int tYear,int tbLastDayMode,"
-"int tbLastDay,int tb30Days,int tbUSMode,int tnDay);\n";
+"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
+"int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
+"int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
+"int tbUSMode,int tnDay);\n";
 
 
 std::string getDiff=
-"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,int fbLastDay,"
-"int fb30Days,int fbUSMode,int fnDay,""int tDay,int tMonth,int tYear,int tbLastDayMode,"
-"int tbLastDay,int tb30Days,int tbUSMode,int tnDay)\n"
-"{\n"
-"if(rFrom>rTo)\n"
-"{\n"
-"int d=fDay;fDay=tDay;tDay=d;\n"
-"int m=fMonth;fMonth=tMonth;tMonth=m;\n"
-"int y=fYear;fYear=tYear;tYear=y;\n"
-"int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
-"int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
-"int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
-"int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
-"int f=fnDay;fnDay=tnDay;tnDay=f;\n"
-"}\n"
-"int nDiff=0;\n"
-"if( tb30Days )\n"
-"{\n"
-"if( tbUSMode )\n"
-"{\n"
-    "if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
-        "tnDay = 31;\n"
-     "else if( (tMonth == 2) && tbLastDay )\n"
-     "tnDay = DaysInMonth( 2, tYear );\n"
-"}\n"
-"else\n"
+"int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
+"int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
+"int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
+"int tbUSMode,int tnDay)\n"
 "{\n"
-     "if( (fMonth == 2) && (fnDay == 30) )\n"
-       "fnDay = DaysInMonth( 2, fYear );\n"
-     "if( (tMonth == 2) && (tnDay == 30) )\n"
-        "tnDay = DaysInMonth( 2, tYear );\n"
-"}\n"
-"}\n"
-"if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
-"{\n"
-"nDiff = (fb30Days? 30:DaysInMonth(fMonth,fYear) )- fnDay + 1;\n"
-"fDay = fnDay = 1;\n"
-"fbLastDay = 0;\n"
-"addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
-"if( fYear < tYear )\n"
-"{\n"
-    "nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
-    "addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear);\n"
-    "nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
-    "fYear+=tYear - fYear;\n"
-"}\n"
-"nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
-"addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear);\n"
-"}\n"
-"nDiff += tnDay - fnDay;\n"
-"return nDiff > 0 ? nDiff : 0;\n"
+"    if(rFrom>rTo)\n"
+"    {\n"
+"        int d=fDay;fDay=tDay;tDay=d;\n"
+"        int m=fMonth;fMonth=tMonth;tMonth=m;\n"
+"        int y=fYear;fYear=tYear;tYear=y;\n"
+"        int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
+"        int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
+"        int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
+"        int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
+"        int f=fnDay;fnDay=tnDay;tnDay=f;\n"
+"    }\n"
+"    int nDiff=0;\n"
+"    if( tb30Days )\n"
+"    {\n"
+"        if( tbUSMode )\n"
+"        {\n"
+"            if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
+"                tnDay = 31;\n"
+"            else if( (tMonth == 2) && tbLastDay )\n"
+"                tnDay = DaysInMonth( 2, tYear );\n"
+"        }\n"
+"        else\n"
+"        {\n"
+"            if( (fMonth == 2) && (fnDay == 30) )\n"
+"                fnDay = DaysInMonth( 2, fYear );\n"
+"            if( (tMonth == 2) && (tnDay == 30) )\n"
+"                tnDay = DaysInMonth( 2, tYear );\n"
+"        }\n"
+"    }\n"
+"    if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
+"    {\n"
+"        nDiff = (fb30Days? 30:DaysInMonth(fMonth,fYear) )- fnDay + 1;\n"
+"        fDay = fnDay = 1;\n"
+"        fbLastDay = 0;\n"
+"        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
+"        if( fYear < tYear )\n"
+"        {\n"
+"            nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
+"            addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
+");\n"
+"            nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
+"            fYear+=tYear - fYear;\n"
+"        }\n"
+"        nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
+"        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
+");\n"
+"    }\n"
+"    nDiff += tnDay - fnDay;\n"
+"    return nDiff > 0 ? nDiff : 0;\n"
 "}\n";
 
 
@@ -399,68 +409,72 @@ std::string lcl_GetcoupdaybsDecl=
 std::string lcl_Getcoupdaybs=
 "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
 "{\n"
-    "int aDate = nMat;\n"
-    "int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,sMonth=0,"
-    "sYear=0;\n"
-    "int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
-    "int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
-    "ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&rbLastDay,"
-    "&rb30Days,&rbUSMode,&rnDay);\n"
-    "ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&sbLastDay,"
-    "&sb30Days,&sbUSMode,&snDay);\n"
-    "rYear= sYear;\n"
-    "nSettle=nSettle+nNullDate;\n"
-    "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "if( aDate < nSettle )\n"
-    "{\n"
-        "rYear+= 1;\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "}\n"
-    "while(aDate > nSettle )\n"
-    "{\n"
-        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear);\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "}\n"
-    "return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, rbLastDay, rb30Days,"
-    "rbUSMode, rnDay,\n"
-    "sDay, sMonth, sYear, sbLastDayMode, sbLastDay, sb30Days, sbUSMode, snDay);\n"
+"    int aDate = nMat;\n"
+"    int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
+"sMonth=0, sYear=0;\n"
+"    int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
+"    int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
+"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
+"rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
+"sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+"    rYear= sYear;\n"
+"    nSettle=nSettle+nNullDate;\n"
+"    aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    if( aDate < nSettle )\n"
+"    {\n"
+"        rYear+= 1;\n"
+"        aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    }\n"
+"    while(aDate > nSettle )\n"
+"    {\n"
+"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
+");\n"
+"        aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    }\n"
+"    return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
+"rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
+"sbLastDay, sb30Days, sbUSMode, snDay);\n"
 "}\n";
 
 std::string lcl_GetcoupdaysDecl=
-"int lcl_Getcoupdays(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
+"int lcl_Getcoupdays(int nNullDate,int nSettle, "
+"int nMat,int nFreq,int nBase);\n";
 
 std::string lcl_Getcoupdays=
-"int lcl_Getcoupdays(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
-"{\n"
-    "int aDate = nMat;\n"
-    "int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
-    "sMonth=0, sYear=0;\n"
-    "int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
-    "int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
-    "ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,"
-    "&rbLastDayMode,&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
-    "ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,"
-    "&sbLastDayMode,&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
-    "rYear= sYear;\n"
-    "nSettle=nSettle+nNullDate;\n"
-    "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "if( aDate < nSettle )\n"
-    "{  \n"
-        "rYear+= 1;\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "}\n"
-    "while(aDate > nSettle )\n"
-    "{\n"
-        "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear);\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "}\n"
-    "int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
-    "int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,"
-    "ab30Days=rb30Days,abUSMode=rbUSMode,anDay=rnDay;\n"
-    "addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
-    "return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode,"
-    "rbLastDay, rb30Days, rbUSMode, rnDay,\n"
-        "aDay, aMonth, aYear, abLastDayMode, abLastDay, ab30Days, abUSMode, anDay);\n"
+"int lcl_Getcoupdays(int nNullDate,int nSettle, "
+"int nMat,int nFreq,int nBase)\n"
+"{\n"
+"    int aDate = nMat;\n"
+"    int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
+"sMonth=0, sYear=0;\n"
+"    int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
+"    int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
+"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
+"rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
+"sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+"    rYear= sYear;\n"
+"    nSettle=nSettle+nNullDate;\n"
+"    aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    if( aDate < nSettle )\n"
+"    {  \n"
+"        rYear+= 1;\n"
+"        aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    }\n"
+"    while(aDate > nSettle )\n"
+"    {\n"
+"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
+");\n"
+"        aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    }\n"
+"    int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
+"    int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
+"abUSMode=rbUSMode,anDay=rnDay;\n"
+"    addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
+"    return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
+"rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
+"abLastDay, ab30Days, abUSMode, anDay);\n"
 "}\n";
 
 
@@ -470,39 +484,40 @@ std::string lcl_GetcoupnumDecl=
 std::string lcl_Getcoupnum=
 "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
 "{\n"
-    "int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;\n"
-    "int sDay=0,sMonth=0, sYear=0;\n"
-    "DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
-    "DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
-    "DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
-    "rYear= sYear;\n"
-    "nSettle=nSettle+nNullDate;\n"
-    "aDate=DateToDays( rDay,rMonth,rYear );\n"
-    "if( aDate < nSettle )\n"
-        "rYear+= 1;\n"
-    "int d=DateToDays( rDay,rMonth,rYear );\n"
-    "int nMonthCount=-1*(12 / nFreq);\n"
-    "while(d > nSettle )\n"
-    "{\n"
-        "int nNewMonth = nMonthCount + rMonth;\n"
-        "if( nNewMonth > 12 )\n"
-        "{\n"
-            "--nNewMonth;\n"
-            "rYear+=nNewMonth / 12;\n"
-            "rMonth = nNewMonth % 12 + 1;\n"
-        "}\n"
-        "else if( nNewMonth < 1 )\n"
-        "{\n"
-            "rYear+= nNewMonth / 12 - 1;\n"
-            "rMonth = nNewMonth % 12 + 12;\n"
-        "}\n"
-        "else\n"
-            "rMonth =  nNewMonth;\n"
-        "d=DateToDays( rDay,rMonth,rYear );\n"
-    "}\n"
-    "int n=(mYear-rYear)*12+mMonth-rMonth;\n"
-    "n=n*nFreq/12;\n"
-    "return n;\n"
+"    int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
+"0;\n"
+"    int sDay=0,sMonth=0, sYear=0;\n"
+"    DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
+"    DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
+"    DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
+"    rYear= sYear;\n"
+"    nSettle=nSettle+nNullDate;\n"
+"    aDate=DateToDays( rDay,rMonth,rYear );\n"
+"    if( aDate < nSettle )\n"
+"        rYear+= 1;\n"
+"    int d=DateToDays( rDay,rMonth,rYear );\n"
+"    int nMonthCount=-1*(12 / nFreq);\n"
+"    while(d > nSettle )\n"
+"    {\n"
+"        int nNewMonth = nMonthCount + rMonth;\n"
+"        if( nNewMonth > 12 )\n"
+"        {\n"
+"            --nNewMonth;\n"
+"            rYear+=nNewMonth / 12;\n"
+"            rMonth = nNewMonth % 12 + 1;\n"
+"        }\n"
+"        else if( nNewMonth < 1 )\n"
+"        {\n"
+"            rYear+= nNewMonth / 12 - 1;\n"
+"            rMonth = nNewMonth % 12 + 12;\n"
+"        }\n"
+"        else\n"
+"            rMonth =  nNewMonth;\n"
+"        d=DateToDays( rDay,rMonth,rYear );\n"
+"    }\n"
+"    int n=(mYear-rYear)*12+mMonth-rMonth;\n"
+"    n=n*nFreq/12;\n"
+"    return n;\n"
 "}\n";
 
 std::string coupdaysDecl=
@@ -512,11 +527,11 @@ std::string coupdaysDecl=
 std::string coupdays=
 "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
 "{\n"
-    "int nNullDate=GetNullDate();\n"
-    "if( nBase == 1 )\n"
-        "return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
-    "else\n"
-        "return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
+"    int nNullDate=GetNullDate();\n"
+"    if( nBase == 1 )\n"
+"        return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
+"    else\n"
+"        return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
 "}\n";
 
 std::string coupdaybsDecl=
@@ -525,8 +540,8 @@ std::string coupdaybsDecl=
 std::string coupdaybs=
 "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
 "{\n"
-    "int nNullDate=GetNullDate();\n"
-    "return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
+"    int nNullDate=GetNullDate();\n"
+"    return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
 "}\n";
 
 std::string coupdaysncDecl=
@@ -534,39 +549,41 @@ std::string coupdaysncDecl=
 
 
 std::string coupdaysnc=
-"double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
+    "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
 "{\n"
-"int nNullDate=GetNullDate();\n"
-"if((nBase != 0) && (nBase != 4))\n"
-"{\n"
-        "int aDate = nMat;\n"
-        "int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0,"
-        "mYear=0;int sDay=0,sMonth=0, sYear=0;\n"
-        "int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
-        "int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
-        "ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,"
-        "&rbLastDayMode,&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
-        "ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,"
-        "&sbLastDayMode,&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
-        "rYear= sYear;\n"
-        "nSettle=nSettle+nNullDate;\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-        "if( aDate > nSettle )\n"
-        "{\n"
-        "rYear-= 1;\n"
-        "aDate=DateToDays( rDay,rMonth,rYear );\n"
-"}\n"
-"while(aDate <= nSettle )\n"
-"{\n"
-    "addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
-    "aDate=DateToDays( rDay,rMonth,rYear );\n"
-"}\n"
-"return getDiff( nSettle, aDate, sDay, sMonth, sYear, "
-"sbLastDayMode, sbLastDay, sb30Days, sbUSMode, snDay,\n"
-    "rDay, rMonth, rYear, rbLastDayMode, rbLastDay, rb30Days, rbUSMode, rnDay);\n"
-"}\n"
-"else\n"
-    "return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,nFreq,nBase);\n"
+"    int nNullDate=GetNullDate();\n"
+"    if((nBase != 0) && (nBase != 4))\n"
+"    {\n"
+"        int aDate = nMat;\n"
+"        int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
+"sMonth=0, sYear=0;\n"
+"        int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
+"        int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
+"        ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
+"rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+"        ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
+"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+"        rYear= sYear;\n"
+"        nSettle=nSettle+nNullDate;\n"
+"        aDate=DateToDays( rDay,rMonth,rYear );\n"
+"        if( aDate > nSettle )\n"
+"        {\n"
+"            rYear-= 1;\n"
+"            aDate=DateToDays( rDay,rMonth,rYear );\n"
+"        }\n"
+"        while(aDate <= nSettle )\n"
+"        {\n"
+"            addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
+";\n"
+"            aDate=DateToDays( rDay,rMonth,rYear );\n"
+"        }\n"
+"        return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
+"sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
+"rbLastDay, rb30Days, rbUSMode, rnDay);\n"
+"    }\n"
+"    else\n"
+"        return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
+"nFreq,nBase);\n"
 "}\n";
 
 std::string coupnumDecl=
@@ -575,8 +592,8 @@ std::string coupnumDecl=
 std::string coupnum=
 "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
 "{\n"
-    "int nNullDate=GetNullDate();\n"
-    "return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
+"    int nNullDate=GetNullDate();\n"
+"    return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
 "}\n";
 
 std::string getPrice_Decl=
@@ -588,18 +605,19 @@ std::string getPrice_=
 "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
     "double fRedemp, int nFreq, int nBase )\n"
 "{\n"
-    "double      fFreq = nFreq;\n"
-    "double      fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
-    "double      fDSC_E = coupdaysnc(  nSettle, nMat, nFreq, nBase ) / fE;\n"
-    "double      fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
-    "double      fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
-    "double      fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + fDSC_E ) );\n"
-    "fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
-    "double      fT1 = 100.0 * fRate / fFreq;\n"
-    "double      fT2 = 1.0 + fYield / fFreq;\n"
-    "for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
-      "fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
-"return fRet;\n"
+"    double      fFreq = nFreq;\n"
+"    double      fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
+"    double      fDSC_E = coupdaysnc(  nSettle, nMat, nFreq, nBase ) / fE;\n"
+"    double      fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
+"    double      fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
+"    double      fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
+"fDSC_E ) );\n"
+"    fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
+"    double      fT1 = 100.0 * fRate / fFreq;\n"
+"    double      fT2 = 1.0 + fYield / fFreq;\n"
+"    for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
+"        fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
+"    return fRet;\n"
 "}\n";
 
 std::string getYield_Decl=
@@ -610,52 +628,59 @@ std::string getYield_=
 "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
 "double fPrice,double fRedemp, int nFreq, int nBase )\n"
 "{\n"
-    "double      fRate = fCoup;\n"
-    "double      fPriceN = 0.0;\n"
-    "double      fYield1 = 0.0;\n"
-    "double      fYield2 = 1.0;\n"
-    "double      fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, nFreq, nBase );\n"
-    "double      fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase );\n"
-    "double      fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
-    "for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ )\n"
-    "{\n"
-        "fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, nBase );\n"
-        "if( fPrice == fPrice1 )\n"
-            "return fYield1;\n"
-        "else if( fPrice == fPrice2 )\n"
-            "return fYield2;\n"
-        "else if( fPrice == fPriceN )\n"
-            "return fYieldN;\n"
-        "else if( fPrice < fPrice2 )\n"
-        "{\n"
-            "fYield2 *= 2.0;\n"
-            "fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase );\n"
-            "fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
-        "}\n"
-        "else\n"
-        "{\n"
-            "if( fPrice < fPriceN )\n"
-            "{\n"
-                "fYield1 = fYieldN;\n"
-                "fPrice1 = fPriceN;\n"
-            "}\n"
-            "else\n"
-            "{\n"
-                "fYield2 = fYieldN;\n"
-                "fPrice2 = fPriceN;\n"
-            "}\n"
-            "fYieldN = fYield2 - ( fYield2 - fYield1 ) * "
-            "( ( fPrice - fPrice2 ) / ( fPrice1 - fPrice2 ) );\n"
-        "}\n"
-    "}\n"
-    "return fYieldN;\n"
+"    double      fRate = fCoup;\n"
+"    double      fPriceN = 0.0;\n"
+"    double      fYield1 = 0.0;\n"
+"    double      fYield2 = 1.0;\n"
+"    double      fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
+"nFreq, nBase );\n"
+"    double      fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
+"nFreq, nBase );\n"
+"    double      fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
+"    for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
+")\n"
+"    {\n"
+"        fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
+"nBase );\n"
+"        if( fPrice == fPrice1 )\n"
+"            return fYield1;\n"
+"        else if( fPrice == fPrice2 )\n"
+"            return fYield2;\n"
+"        else if( fPrice == fPriceN )\n"
+"            return fYieldN;\n"
+"        else if( fPrice < fPrice2 )\n"
+"        {\n"
+"            fYield2 *= 2.0;\n"
+"            fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
+", nBase );\n"
+"            fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
+"        }\n"
+"        else\n"
+"        {\n"
+"            if( fPrice < fPriceN )\n"
+"            {\n"
+"                fYield1 = fYieldN;\n"
+"                fPrice1 = fPriceN;\n"
+"            }\n"
+"            else\n"
+"            {\n"
+"                fYield2 = fYieldN;\n"
+"                fPrice2 = fPriceN;\n"
+"            }\n"
+"            fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
+") / ( fPrice1 - fPrice2 ) );\n"
+"        }\n"
+"    }\n"
+"    return fYieldN;\n"
 "}\n";
 
 std::string GetYearFracDecl=
-"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate, int nMode );\n";
+"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
+"int nMode );\n";
 
 std::string GetYearFrac=
-"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate, int nMode ) \n"
+"double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
+"int nMode ) \n"
 "{\n"
 "    if( nStartDate == nEndDate )\n"
 "        return 0.0;     \n"
@@ -673,8 +698,10 @@ std::string GetYearFrac=
   "  int  nDay1, nDay2;\n"
   "  int  nMonth1, nMonth2;\n"
   "  int  nYear1, nYear2;\n"
+
   "  DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
   "  DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
+
   "  int nDayDiff;\n"
   "  switch( nMode )\n"
   "  {\n"
@@ -689,10 +716,12 @@ std::string GetYearFrac=
   "          }\n"
   "          else\n"
   "          {\n"
-  "              if ( nMonth1 == 2 && nDay1 == ( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
+  "              if ( nMonth1 == 2 && nDay1 == "
+  "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
   "              {\n"
   "                  nDay1 = 30;\n"
-  "                  if ( nMonth2 == 2 && nDay2 == ( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
+  "                  if ( nMonth2 == 2 && nDay2 == "
+  "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
   "                  {\n"
   "                      nDay2 = 30;\n"
   "                  }\n"
@@ -736,20 +765,25 @@ std::string GetYearFrac=
   "                     ( nMonth1 < nMonth2 ) ||\n"
   "                     ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
   "              {\n"
+
   "                  int nDayCount = 0;\n"
-   "                 for ( int i = nYear1; i <= nYear2; i++ )\n"
+  "                 for ( int i = nYear1; i <= nYear2; i++ )\n"
   "                      nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
-  "                  nDaysInYear = ( double ) nDayCount / ( double ) ( nYear2 - nYear1 + 1 );\n"
+
+  "                  nDaysInYear = ( double ) nDayCount / "
+  "( double ) ( nYear2 - nYear1 + 1 );\n"
   "              }\n"
-   "             else\n"
+  "             else\n"
   "              {\n"
   "                  if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
   "                  {\n"
   "                      nDaysInYear = 366;\n"
   "                  }\n"
- "                   else\n"
+  "                   else\n"
   "                  {\n"
-  "                      if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 && nDay1 <= 29 ) ||\n"
+
+  "                      if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
+  "&& nDay1 <= 29 ) ||\n"
   "                           ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
   "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
    "                     {\n"
@@ -787,16 +821,16 @@ std::string GetYieldmatDecl=
 std::string GetYieldmat=
     "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
         "double fRate, double fPrice, int nBase )\n"
-    "{\n"
-        "double      fIssMat = GetYearFrac( nNullDate, nIssue, nMat, nBase );\n"
-        "double      fIssSet = GetYearFrac( nNullDate, nIssue, nSettle, nBase );\n"
-        "double      fSetMat = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
-        "double      y = 1.0 + fIssMat * fRate;\n"
-        "y /= fPrice / 100.0 + fIssSet * fRate;\n"
-        "y-=1.0;\n"
-        "y /= fSetMat;\n"
-        "return y;\n"
-    "}\n";
+"{\n"
+"    double      fIssMat = GetYearFrac( nNullDate, nIssue, nMat, nBase );\n"
+"    double      fIssSet = GetYearFrac( nNullDate, nIssue, nSettle, nBase );\n"
+"    double      fSetMat = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
+"    double      y = 1.0 + fIssMat * fRate;\n"
+"    y /= fPrice / 100.0 + fIssSet * fRate;\n"
+"    y-=1.0;\n"
+"    y /= fSetMat;\n"
+"    return y;\n"
+"}\n";
 
 std::string GetDiffDateDecl=
 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
@@ -806,71 +840,73 @@ std::string GetDiffDate=
 "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
 "    int* pOptDaysIn1stYear )\n"
 "{\n"
-"\t   bool    bNeg = nStartDate > nEndDate;\n"
-
-"\t    if( bNeg )\n"
-"\t    {\n"
-"\t\t        int   n = nEndDate;\n"
-"\t\t        nEndDate = nStartDate;\n"
-"\t\t        nStartDate = n;\n"
-"\t    }\n"
-"\t    int       nRet;\n"
-"\t    switch( nMode )\n"
-"\t    {\n"
-"\t\t       case 0:   \n"
-"\t\t       case 4:   \n"
-"\t\t            {\n"
-"\t\t\t            int      nD1, nM1, nY1, nD2, nM2, nY2;\n"
-"\t\t\t            nStartDate += nNullDate;\n"
-"\t\t\t            nEndDate += nNullDate;\n"
-"\t\t\t            DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
-"\t\t\t            DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
-"\t\t\t            bool        bLeap = IsLeapYear( nY1 );\n"
-"\t\t\t            int       nDays, nMonths;\n"
-"\t\t\t            nMonths = nM2 - nM1;\n"
-"\t\t\t            nDays = nD2 - nD1;\n"
-"\t\t\t            nMonths += ( nY2 - nY1 ) * 12;\n"
-"\t\t\t            nRet = nMonths * 30 + nDays;\n"
-"\t\t\t            if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
-"\t\t\t\t                nRet -= bLeap? 1 : 2;\n"
-"\t\t\t            if( pOptDaysIn1stYear )\n"
-"\t\t\t\t                *pOptDaysIn1stYear = 360;\n"
-"\t\t            }\n"
-"\t\t\t           break;\n"
-"\t\t        case 1:    \n"
-"\t\t\t           if( pOptDaysIn1stYear )\n"
-"\t\t\t            {\n"
-"\t\t\t\t                int      nD, nM, nY;\n"
-"\t\t\t\t                DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
-"\t\t\t\t                *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
-"\t\t\t           }\n"
-"\t\t\t            nRet = nEndDate - nStartDate;\n"
-"\t\t\t            break;\n"
-"\t\t        case 2:      \n"
-"\t\t\t            nRet = nEndDate - nStartDate;\n"
-"\t\t\t            if( pOptDaysIn1stYear )\n"
-"\t\t\t\t                *pOptDaysIn1stYear = 360;\n"
-"\t\t\t            break;\n"
-"\t\t        case 3:        \n"
-"\t\t\t            nRet = nEndDate - nStartDate;\n"
-"\t\t\t            if( pOptDaysIn1stYear )\n"
-"\t\t\t\t                *pOptDaysIn1stYear = 365;\n"
-"\t\t\t            break;\n"
-"\t    }\n"
-"\t    return bNeg? -nRet : nRet;\n"
+"    bool    bNeg = nStartDate > nEndDate;\n"
+"    if( bNeg )\n"
+"    {\n"
+"        int   n = nEndDate;\n"
+"        nEndDate = nStartDate;\n"
+"        nStartDate = n;\n"
+"    }\n"
+"    int       nRet;\n"
+"    switch( nMode )\n"
+"    {\n"
+"    case 0:   \n"
+"    case 4:   \n"
+"        {\n"
+"        int      nD1, nM1, nY1, nD2, nM2, nY2;\n"
+"        nStartDate += nNullDate;\n"
+"        nEndDate += nNullDate;\n"
+"        DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
+"        DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
+"        bool        bLeap = IsLeapYear( nY1 );\n"
+"        int       nDays, nMonths;\n"
+"        nMonths = nM2 - nM1;\n"
+"        nDays = nD2 - nD1;\n"
+"        nMonths += ( nY2 - nY1 ) * 12;\n"
+"        nRet = nMonths * 30 + nDays;\n"
+"        if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
+"            nRet -= bLeap? 1 : 2;\n"
+"        if( pOptDaysIn1stYear )\n"
+"            *pOptDaysIn1stYear = 360;\n"
+"        }\n"
+"        break;\n"
+"    case 1:    \n"
+"        if( pOptDaysIn1stYear )\n"
+"        {\n"
+"            int      nD, nM, nY;\n"
+"            DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
+"            *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
+"        }\n"
+"        nRet = nEndDate - nStartDate;\n"
+"        break;\n"
+"    case 2:      \n"
+"        nRet = nEndDate - nStartDate;\n"
+"        if( pOptDaysIn1stYear )\n"
+"            *pOptDaysIn1stYear = 360;\n"
+"        break;\n"
+"    case 3:        \n"
+"        nRet = nEndDate - nStartDate;\n"
+"        if( pOptDaysIn1stYear )\n"
+"            *pOptDaysIn1stYear = 365;\n"
+"        break;\n"
+"    }\n"
+"    return bNeg? -nRet : nRet;\n"
 "}\n";
 
 std::string GetYearDiffDecl=
-"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate, int nMode);\n";
+"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
+"int nMode);\n";
 
 std::string GetYearDiff=
-"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate, int nMode )\n"
-"{\n"
-"\t    int   nDays1stYear;\n"
-"\t    int   nTotalDays = GetDiffDate( nNullDate, nStartDate,"
-"nEndDate, nMode, &nDays1stYear );\n"
-"\t    double result=(double)(nTotalDays)/(nDays1stYear);\n"
-"\treturn result;\n"
+"double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
+"int nMode )\n"
+"{\n"
+"    int   nDays1stYear;\n"
+"    int   nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
+"nMode, &"
+"nDays1stYear );\n"
+"    double result=(double)(nTotalDays)/(nDays1stYear);\n"
+"    return result;\n"
 "}\n";
 
 std::string GetDiffDate360_Decl=
@@ -887,9 +923,9 @@ std::string GetDiffDate360_=
 "{\n"
 "    if( nDay1 == 31 )\n"
 "        nDay1--;\n"
-"    else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 ||"
-"( nDay1 == 28 && !bLeapYear1 ) ) ) )\n"
-"            nDay1 = 30;\n"
+"    else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
+"&& !bLeapYear1 ) ) ) )\n"
+"        nDay1 = 30;\n"
 "    if( nDay2 == 31 )\n"
 "    {\n"
 "        if( bUSAMethod && nDay1 != 30 )\n"
@@ -906,23 +942,26 @@ std::string GetDiffDate360_=
 "        else\n"
 "            nDay2 = 30;\n"
 "    }\n"
-"    return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - nYear1 * 360;\n"
+"    return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
+"nYear1 * 360;\n"
 "}\n";
 
 std::string GetDiffDate360Decl=
-"int GetDiffDate360( int nNullDate, int nDate1, int nDate2, bool bUSAMethod);\n";
+"int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
+"bool bUSAMethod);\n";
 
 
 std::string GetDiffDate360=
-"int GetDiffDate360( int nNullDate, int nDate1, int nDate2, bool bUSAMethod )\n"
+"int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
+"bool bUSAMethod )\n"
 "{\n"
 "    nDate1 += nNullDate;\n"
 "    nDate2 += nNullDate;\n"
 "    int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
 "    DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
 "    DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
-"    return GetDiffDate360_( nDay1, nMonth1, nYear1, "
-"IsLeapYear( nYear1 ), nDay2, nMonth2, nYear2, bUSAMethod );\n"
+"    return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
+"nDay2, nMonth2, nYear2, bUSAMethod );\n"
 "}\n";
 
 #endif


More information about the Libreoffice-commits mailing list