LCOV - code coverage report
Current view: top level - sc/source/core/opencl - opinlinefun_finacial.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 126 0.0 %
Date: 2014-04-14 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef SC_OPENCL_OPINLINFUN_finacial
      11             : #define SC_OPENCL_OPINLINFUN_finacial
      12           0 : std::string approxEqualDecl="bool approxEqual(double a, double b);\n";
      13           0 : std::string approxEqual =
      14             : "bool approxEqual(double a, double b)\n"
      15             : "{\n"
      16             : "     if (a == b)\n"
      17             : "        return true;\n"
      18             : "     double x = a - b;\n"
      19             : "     return (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 *"
      20             : "16777216.0)));\n"
      21             : "}\n";
      22             : 
      23           0 : std::string nKorrValDecl ="double constant nKorrVal[]"
      24             : "= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, "
      25             : "9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n";
      26             : 
      27           0 : std::string SCdEpsilonDecl =
      28             : "constant double SCdEpsilon = 1.0E-7;\n";
      29             : 
      30           0 : std::string RoundDecl = "double  Round(double fValue);\n";
      31             : 
      32           0 : std::string Round =
      33             : "double  Round(double fValue)\n"
      34             : "{\n"
      35             : "    if ( fValue == 0.0  )\n"
      36             : "        return fValue;\n"
      37             : "\n"
      38             : "    double fFac = 0;\n"
      39             : "    int nExp;\n"
      40             : "    if ( fValue > 0.0 )\n"
      41             : "        nExp = ( floor( log10( fValue ) ) );\n"
      42             : "    else\n"
      43             : "        nExp = 0;\n"
      44             : "    int nIndex = 15 - nExp;\n"
      45             : "    if ( nIndex > 15 )\n"
      46             : "        nIndex = 15;\n"
      47             : "    else if ( nIndex <= 1 )\n"
      48             : "        nIndex = 0;\n"
      49             : "    fValue = floor( fValue + 0.5 + nKorrVal[nIndex] );\n"
      50             : "    return fValue;\n"
      51             : "}\n";
      52             : 
      53           0 : std::string GetRmzDecl =
      54             : "double GetRmz( double fZins, double fZzr, double fBw, double fZw,int nF );\n";
      55             : 
      56           0 : std::string GetRmz=
      57             : "double GetRmz( double fZins, double fZzr, double fBw, double fZw, int nF )\n"
      58             : "{\n"
      59             : "    double      fRmz;\n"
      60             : "    if( fZins == 0.0 )\n"
      61             : "        fRmz = ( fBw + fZw ) / fZzr;\n"
      62             : "    else\n"
      63             : "    {\n"
      64             : "        double  fTerm = pow( 1.0 + fZins, fZzr );\n"
      65             : "        if( nF > 0 )\n"
      66             : "            fRmz = ( fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins / ( 1.0 - 1."
      67             : "0 / fTerm ) ) / ( 1.0 + fZins );\n"
      68             : "        else\n"
      69             : "            fRmz = fZw * fZins / ( fTerm - 1.0 ) + fBw * fZins /( 1.0 - 1.0 "
      70             : "/ fTerm );\n"
      71             : "    }\n"
      72             : "    return -fRmz;\n"
      73             : "}\n";
      74             : 
      75           0 : std::string GetRmz_newDecl =
      76             : "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
      77             : "int nF );\n";
      78           0 : std::string GetRmz_new=
      79             : "double GetRmz_new( double fZins, double fZzr, double fBw, double fZw,"
      80             : "int nF)\n"
      81             : "{\n"
      82             : "    double fRmz;\n"
      83             : "        double  fTerm = pow( 1.0 + fZins, fZzr );\n"
      84             : "        if( nF > 0 )\n"
      85             : "            fRmz = ( fZw * fZins *pow ( fTerm - 1.0,-1 ) + fBw * fZins *pow( "
      86             : "( 1.0 - pow( fTerm,-1) ),-1) )* pow ( 1.0 + fZins,-1 );\n"
      87             : "        else\n"
      88             : "            fRmz = fZw * fZins *pow ( fTerm - 1.0 ,-1) + fBw * fZins *pow( "
      89             : "1.0 - pow( fTerm,-1),-1 );\n"
      90             : "    return -fRmz;\n"
      91             : "}\n";
      92           0 : std::string GetZwDecl =
      93             : "double GetZw( double fZins, double fZzr, double fRmz,"
      94             : "double fBw, int nF );\n";
      95             : 
      96           0 : std::string GetZw =
      97             : "double GetZw( double fZins, double fZzr, double fRmz,"
      98             : "double fBw, int nF )\n"
      99             : "{\n"
     100             : "    double      fZw;\n"
     101             : "    if( fZins == 0.0 )\n"
     102             : "        fZw = fBw + fRmz * fZzr;\n"
     103             : "    else\n"
     104             : "    {\n"
     105             : "        double  fTerm = pow( 1.0 + fZins, fZzr );\n"
     106             : "        if( nF > 0 )\n"
     107             : "                fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
     108             : "/ fZins;\n"
     109             : "        else\n"
     110             : "                fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) / fZins;\n"
     111             : "    }\n"
     112             : "    return -fZw;\n"
     113             : "}\n";
     114             : 
     115           0 : std::string GetZw_newDecl =
     116             : "double GetZw_new( double fZins, double fZzr, double fRmz,"
     117             : "double fBw, int nF );\n";
     118             : 
     119           0 : std::string GetZw_new =
     120             : "double GetZw_new( double fZins, double fZzr, double fRmz,"
     121             : "double fBw, int nF )\n"
     122             : "{\n"
     123             : "    double fZw;\n"
     124             : "    double  fTerm = pow( 1.0 + fZins, fZzr );\n"
     125             : "    if( nF > 0 )\n"
     126             : "        fZw = fBw * fTerm + fRmz * ( 1.0 + fZins ) *( fTerm - 1.0 ) "
     127             : "*pow( fZins,-1);\n"
     128             : "    else\n"
     129             : "        fZw = fBw * fTerm + fRmz * ( fTerm - 1.0 ) *pow( fZins,-1);\n"
     130             : "    return -fZw;\n"
     131             : "}\n";
     132             : 
     133           0 : std::string IsLeapYearDecl =
     134             : "bool IsLeapYear( int n );\n";
     135             : 
     136           0 : std::string IsLeapYear =
     137             : "bool IsLeapYear( int n )\n"
     138             : "{\n"
     139             : "    return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == "
     140             : "0 ) );\n"
     141             : "}\n";
     142             : 
     143           0 : std::string DaysInMonthDecl=
     144             : "int DaysInMonth( int nMonth, int nYear );\n";
     145             : 
     146           0 : std::string DaysInMonth =
     147             : "int DaysInMonth( int nMonth, int nYear )\n"
     148             : "{\n"
     149             : "    int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n"
     150             : "                31, 31, 30, 31, 30, 31 };\n"
     151             : "\n"
     152             : "    if ( nMonth != 2 )\n"
     153             : "        return aDaysInMonth[nMonth-1];\n"
     154             : "    else\n"
     155             : "    {\n"
     156             : "        if ( IsLeapYear(nYear) )\n"
     157             : "            return aDaysInMonth[nMonth-1] + 1;\n"
     158             : "        else\n"
     159             : "            return aDaysInMonth[nMonth-1];\n"
     160             : "    }\n"
     161             : "}\n";
     162           0 : std::string DaysInMonth_newDecl=
     163             : "int DaysInMonth( int nMonth, int nYear );\n";
     164             : 
     165           0 : std::string DaysInMonth_new =
     166             : "int DaysInMonth( int nMonth, int nYear )\n"
     167             : "{\n"
     168             : "    int tmp = 0;\n"
     169             : "    switch(nMonth)\n"
     170             : "    {\n"
     171             : "    case 1:\n"
     172             : "    case 3:\n"
     173             : "    case 5:\n"
     174             : "    case 7:\n"
     175             : "    case 8:\n"
     176             : "    case 10:\n"
     177             : "    case 12:\n"
     178             : "        tmp = 31;\n"
     179             : "        break;\n"
     180             : "    case 4:\n"
     181             : "    case 6:\n"
     182             : "    case 9:\n"
     183             : "    case 11:\n"
     184             : "        tmp =30;\n"
     185             : "        break;\n"
     186             : "    case 2:\n"
     187             : "        if ( IsLeapYear(nYear)==1)\n"
     188             : "            tmp = 29;\n"
     189             : "        else\n"
     190             : "            tmp = 28;\n"
     191             : "        break;\n"
     192             : "    }\n"
     193             : "    return tmp;\n"
     194             : "}\n";
     195             : 
     196           0 : std::string DaysToDateDecl =
     197             : "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
     198             : 
     199           0 : std::string DaysToDate =
     200             : "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
     201             : "{\n"
     202             : "\n"
     203             : "    int   nTempDays;\n"
     204             : "    int   i = 0;\n"
     205             : "    bool    bCalc;\n"
     206             : 
     207             : "    do\n"
     208             : "    {\n"
     209             : "        nTempDays = nDays;\n"
     210             : "        *rYear = (int)((nTempDays / 365) - i);\n"
     211             : "        nTempDays -= ((int) *rYear -1) * 365;\n"
     212             : "        nTempDays -= (( *rYear -1) / 4) - (( *rYear -1) / 100) +"
     213             : "((*rYear -1) / 400);\n"
     214             : "        bCalc = false;\n"
     215             : "        if ( nTempDays < 1 )\n"
     216             : "        {\n"
     217             : "            i++;\n"
     218             : "            bCalc = true;\n"
     219             : "        }\n"
     220             : "        else\n"
     221             : "        {\n"
     222             : "            if ( nTempDays > 365 )\n"
     223             : "            {\n"
     224             : "                if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
     225             : "                {\n"
     226             : "                    i--;\n"
     227             : "                    bCalc = true;\n"
     228             : "                }\n"
     229             : "            }\n"
     230             : "        }\n"
     231             : "    }\n"
     232             : "    while ( bCalc );\n"
     233             : "     if(nTempDays!=0){\n"
     234             : "      for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
     235             : "*rMonth+=1)\n"
     236             : "      {\n"
     237             : "       nTempDays -= DaysInMonth( *rMonth, *rYear );\n"
     238             : "      }\n"
     239             : "      *rDay = (int)nTempDays;\n"
     240             : "     }\n"
     241             : "}\n";
     242             : 
     243           0 : std::string DateToDaysDecl=
     244             : "int  DateToDays( int nDay, int nMonth, int nYear );\n";
     245             : 
     246           0 : std::string DateToDays=
     247             : "int  DateToDays( int nDay, int nMonth, int nYear )\n"
     248             : "{\n"
     249             : "    int nDays = ((int)nYear-1) * 365;\n"
     250             : "    nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);\n"
     251             : "    for( int i = 1; i < nMonth; i++ )\n"
     252             : "        nDays += DaysInMonth(i,nYear);\n"
     253             : "    nDays += nDay;\n"
     254             : "\n"
     255             : "    return nDays;\n"
     256             : "}\n";
     257             : 
     258           0 : std::string DateToDays_newDecl=
     259             : "int  DateToDays_new( int nDay, int nMonth, int nYear );\n";
     260             : 
     261           0 : std::string DateToDays_new=
     262             : "int  DateToDays_new( int nDay, int nMonth, int nYear )\n"
     263             : "{\n"
     264             : "    int nDays = (nYear-1) * 365;\n"
     265             : "    nDays += (int)((nYear-1) *pow(4.0,-1.0)- (nYear-1) *pow( 100.0,-1.0)"
     266             : "+ (nYear-1) *pow(400.0,-1.0));\n"
     267             : "    for( int i = 1; i < nMonth; i++ )\n"
     268             : "        nDays += DaysInMonth(i,nYear);\n"
     269             : "    nDays += nDay;\n"
     270             : "\n"
     271             : "    return nDays;\n"
     272             : "}\n";
     273             : 
     274             : 
     275           0 : std::string GetNullDateDecl=
     276             : "int GetNullDate(void);\n";
     277             : 
     278           0 : std::string GetNullDate=
     279             : "int GetNullDate(void)\n"
     280             : "{\n"
     281             : "    return DateToDays(30,12,1899 );\n"
     282             : "}\n";
     283           0 : std::string GetNullDate_newDecl=
     284             : "int GetNullDate_new(void);\n";
     285             : 
     286           0 : std::string GetNullDate_new=
     287             : "int GetNullDate_new(void)\n"
     288             : "{\n"
     289             : "    return DateToDays_new(30,12,1899 );\n"
     290             : "}\n";
     291             : 
     292           0 : std::string ScaDateDecl=
     293             : "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
     294             : "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
     295             : "int *b30Days,int *bUSMode,int *nDay);\n";
     296             : 
     297           0 : std::string ScaDate=
     298             : "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, "
     299             : "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay,"
     300             : "int *b30Days,int *bUSMode,int *nDay)\n"
     301             : "{\n"
     302             : "    DaysToDate( nNullDate + nDate, nOrigDay, nMonth, nYear );\n"
     303             : "    *bLastDayMode = (nBase != 5);\n"
     304             : "    *bLastDay = (*nOrigDay >= DaysInMonth( *nMonth, *nYear ));\n"
     305             : "    *b30Days = (nBase == 0) || (nBase == 4);\n"
     306             : "    *bUSMode = (nBase == 0);\n"
     307             : "    if( *b30Days)\n"
     308             : "    {\n"
     309             : "        *nDay = min( *nOrigDay, 30);\n"
     310             : "        if( *bLastDay || (*nDay >=DaysInMonth( *nMonth, *nYear )) )\n"
     311             : "        *nDay = 30;\n"
     312             : "    }\n"
     313             : "    else\n"
     314             : "    {\n"
     315             : "        int nLastDay = DaysInMonth( *nMonth, *nYear );\n"
     316             : "        *nDay = *bLastDay ? nLastDay : min( *nOrigDay, nLastDay );\n"
     317             : "    }\n"
     318             : "}\n";
     319             : 
     320           0 : std::string ScaDate2Decl=
     321             : "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
     322             : "bLastDay,int *b30Days,int *bUSMode);\n";
     323             : 
     324           0 : std::string ScaDate2=
     325             : "void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
     326             : "bLastDay,int *b30Days,int *bUSMode)\n"
     327             : "{\n"
     328             : "    int nOrigDay=0,  nMonth=0,  nYear=0;\n"
     329             : "    DaysToDate( nNullDate + nDate, &nOrigDay, &nMonth, &nYear );\n"
     330             : "    *bLastDayMode = (nBase != 5);\n"
     331             : "    *bLastDay = (nOrigDay >= DaysInMonth( nMonth, nYear ));\n"
     332             : "    *b30Days = (nBase == 0) || (nBase == 4);\n"
     333             : "    *bUSMode = (nBase == 0);\n"
     334             : "}\n";
     335             : 
     336           0 : std::string lcl_GetCouppcdDecl=
     337             : "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
     338             : 
     339           0 : std::string lcl_GetCouppcd=
     340             : "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
     341             : "{\n"
     342             : "    int aDate = nMat;\n"
     343             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     344             : "rbUSMode=0,rnDay=0;\n"
     345             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     346             : "sbUSMode=0,snDay=0;\n"
     347             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     348             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     349             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     350             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     351             : "    rYear=sYear;\n"
     352             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     353             : "    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
     354             : "sbLastDay,rDay,sDay))\n"
     355             : "    {\n"
     356             : "        rYear+=1;\n"
     357             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     358             : "    }\n"
     359             : "    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     360             : "rbLastDay,sDay,rDay))\n"
     361             : "    {\n"
     362             : "        double d = -1*(12/nFreq);\n"
     363             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
     364             : "    }\n"
     365             : "    int nLastDay = DaysInMonth( rMonth, rYear );\n"
     366             : "    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
     367             : "min( nLastDay, rDay );\n"
     368             : "    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
     369             : "}\n";
     370             : 
     371           0 : std::string lcl_GetCoupncdDecl=
     372             : "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
     373             : 
     374           0 : std::string lcl_GetCoupncd=
     375             : "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
     376             : "{\n"
     377             : "    int aDate = nMat;\n"
     378             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     379             : "rbUSMode=0,rnDay=0;\n"
     380             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     381             : "sbUSMode=0,snDay=0;\n"
     382             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     383             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     384             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     385             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     386             : "    rYear=sYear;\n"
     387             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     388             : "    if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
     389             : ",sDay,rDay))\n"
     390             : "    {\n"
     391             : "        rYear-=1;\n"
     392             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     393             : "    }\n"
     394             : "    while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     395             : "rbLastDay,sDay,rDay))\n"
     396             : "    {\n"
     397             : "      addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
     398             : "    }\n"
     399             : "    int nLastDay = DaysInMonth( rMonth, rYear );\n"
     400             : "    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
     401             : "min( nLastDay, rDay );\n"
     402             : "    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
     403             : "}\n";
     404             : 
     405           0 : std::string addMonthsDecl=
     406             : "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
     407             : "int *nMonth,int nMonthCount,int *year);\n";
     408             : 
     409           0 : std::string addMonths=
     410             : "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
     411             : "int *nMonth,int nMonthCount,int *year)\n"
     412             : "{\n"
     413             : "    int nNewMonth = nMonthCount + *nMonth;\n"
     414             : "    if( nNewMonth > 12 )\n"
     415             : "    {\n"
     416             : "        --nNewMonth;\n"
     417             : "        *year+=nNewMonth / 12 ;\n"
     418             : "        *nMonth = ( nNewMonth % 12 ) + 1;\n"
     419             : "    }\n"
     420             : "    else if( nNewMonth < 1 )\n"
     421             : "    {\n"
     422             : "        *year+= nNewMonth / 12 - 1 ;\n"
     423             : "        *nMonth =  nNewMonth % 12 + 12 ;\n"
     424             : "    }\n"
     425             : "    else\n"
     426             : "        *nMonth = nNewMonth ;\n"
     427             : "    if( b30Days )\n"
     428             : "    {\n"
     429             : "        *nDay = min( nOrigDay, 30);\n"
     430             : "        if( bLastDay || (*nDay >= DaysInMonth( *nMonth, *year )) )\n"
     431             : "            *nDay = 30;\n"
     432             : "    }\n"
     433             : "    else\n"
     434             : "    {\n"
     435             : "        int nLastDay = DaysInMonth( *nMonth, *year );\n"
     436             : "        *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
     437             : "    }\n"
     438             : "}\n";
     439             : 
     440           0 : std::string getDaysInMonthRangeDecl=
     441             : "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n";
     442             : 
     443           0 : std::string getDaysInMonthRange=
     444             : "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n"
     445             : "{\n"
     446             : "    if( nFrom > nTo )\n"
     447             : "        return 0;\n"
     448             : "    int nRet = 0;\n"
     449             : "    if( b30Days )\n"
     450             : "        nRet = (nTo - nFrom + 1) * 30;\n"
     451             : "    else\n"
     452             : "    {\n"
     453             : "        for( int nMonthIx = nFrom; nMonthIx <= nTo; ++nMonthIx )\n"
     454             : "            nRet += b30Days ? 30 : DaysInMonth( nMonthIx, year );\n"
     455             : "    }\n"
     456             : "    return nRet;\n"
     457             : "}\n";
     458             : 
     459           0 : std::string GetDaysInYearsDecl=
     460             : "int GetDaysInYears( int nYear1, int nYear2 );\n";
     461             : 
     462           0 : std::string GetDaysInYears=
     463             : "int GetDaysInYears( int nYear1, int nYear2 )\n"
     464             : "{\n"
     465             : "    int  nLeaps = 0;\n"
     466             : "    for( int n = nYear1 ; n <= nYear2 ; n++ )\n"
     467             : "    {\n"
     468             : "        if( IsLeapYear( n ) )\n"
     469             : "            nLeaps++;\n"
     470             : "    }\n"
     471             : "    int  nSum = 1;\n"
     472             : "    nSum += nYear2;\n"
     473             : "    nSum -= nYear1;\n"
     474             : "    nSum *= 365;\n"
     475             : "    nSum += nLeaps;\n"
     476             : "    return nSum;\n"
     477             : "}\n";
     478             : 
     479           0 : std::string GetDaysInYearDecl=
     480             : "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n";
     481             : 
     482           0 : std::string GetDaysInYear=
     483             : "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n"
     484             : "{\n"
     485             : "    switch( nMode )\n"
     486             : "    {\n"
     487             : "    case 0:\n"
     488             : "    case 2:\n"
     489             : "    case 4:\n"
     490             : "        return 360;\n"
     491             : "    case 1:\n"
     492             : "        {\n"
     493             : "            int  nD=0, nM=0, nY=0;\n"
     494             : "            nDate += nNullDate;\n"
     495             : "            DaysToDate( nDate, &nD, &nM, &nY );\n"
     496             : "            return IsLeapYear( nY )? 366 : 365;\n"
     497             : "        }\n"
     498             : "    case 3:\n"
     499             : "        return 365;\n"
     500             : "    }\n"
     501             : "}\n";
     502             : 
     503           0 : std::string getDaysInYearRangeDecl =
     504             : "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n";
     505             : 
     506           0 : std::string getDaysInYearRange=
     507             : "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n"
     508             : "{\n"
     509             : "    if( nFrom > nTo )\n"
     510             : "        return 0;\n"
     511             : "    return b30Days ? ((nTo - nFrom + 1) * 360) : GetDaysInYears( nFrom, nTo)"
     512             : ";\n"
     513             : "}\n";
     514             : 
     515             : 
     516           0 : std::string getDiffDecl=
     517             : "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
     518             : "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
     519             : "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
     520             : "int tbUSMode,int tnDay);\n";
     521             : 
     522             : 
     523           0 : std::string getDiff=
     524             : "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode,"
     525             : "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth,"
     526             : "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days,"
     527             : "int tbUSMode,int tnDay)\n"
     528             : "{\n"
     529             : "    if(rFrom>rTo)\n"
     530             : "    {\n"
     531             : "        int d=fDay;fDay=tDay;tDay=d;\n"
     532             : "        int m=fMonth;fMonth=tMonth;tMonth=m;\n"
     533             : "        int y=fYear;fYear=tYear;tYear=y;\n"
     534             : "        int a=fbLastDayMode;fbLastDayMode=tbLastDayMode;tbLastDayMode=a;\n"
     535             : "        int b=fbLastDay;fbLastDay=tbLastDay;tbLastDay=b;\n"
     536             : "        int c=fb30Days;fb30Days=tb30Days;tb30Days=c;\n"
     537             : "        int e=fbUSMode;fbUSMode=tbUSMode;tbUSMode=e;\n"
     538             : "        int f=fnDay;fnDay=tnDay;tnDay=f;\n"
     539             : "    }\n"
     540             : "    int nDiff=0;\n"
     541             : "    if( tb30Days )\n"
     542             : "    {\n"
     543             : "        if( tbUSMode )\n"
     544             : "        {\n"
     545             : "            if( ((fMonth == 2) || (fnDay < 30)) && (tDay == 31) )\n"
     546             : "                tnDay = 31;\n"
     547             : "            else if( (tMonth == 2) && tbLastDay )\n"
     548             : "                tnDay = DaysInMonth( 2, tYear );\n"
     549             : "        }\n"
     550             : "        else\n"
     551             : "        {\n"
     552             : "            if( (fMonth == 2) && (fnDay == 30) )\n"
     553             : "                fnDay = DaysInMonth( 2, fYear );\n"
     554             : "            if( (tMonth == 2) && (tnDay == 30) )\n"
     555             : "                tnDay = DaysInMonth( 2, tYear );\n"
     556             : "        }\n"
     557             : "    }\n"
     558             : "    if( (fYear < tYear) || ((fYear == tYear) && (fMonth < tMonth)) )\n"
     559             : "    {\n"
     560             : "        int d = fb30Days ? 30:DaysInMonth(fMonth,fYear);\n"
     561             : "        nDiff = d- fnDay + 1;\n"
     562             : "        fDay = fnDay = 1;\n"
     563             : "        fbLastDay = 0;\n"
     564             : "        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,1,&fYear);\n"
     565             : "        if( fYear < tYear )\n"
     566             : "        {\n"
     567             : "            nDiff += getDaysInMonthRange( fMonth, 12,fb30Days,fYear);\n"
     568             : "            addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,13-fMonth,&fYear"
     569             : ");\n"
     570             : "            nDiff += getDaysInYearRange( fYear, tYear - 1,fb30Days);\n"
     571             : "            fYear+=tYear - fYear;\n"
     572             : "        }\n"
     573             : "        nDiff += getDaysInMonthRange(fMonth, tMonth - 1,fb30Days ,fYear );\n"
     574             : "        addMonths(fb30Days,fbLastDay,&fnDay,fDay,&fMonth,tMonth-fMonth,&fYear"
     575             : ");\n"
     576             : "    }\n"
     577             : "    nDiff += tnDay - fnDay;\n"
     578             : "    return nDiff > 0 ? nDiff : 0;\n"
     579             : "}\n";
     580             : 
     581           0 : std::string lcl_GetcoupdaybsDecl=
     582             : "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n";
     583             : 
     584             : 
     585           0 : std::string lcl_Getcoupdaybs=
     586             : "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
     587             : "{\n"
     588             : "    int aDate = nMat;\n"
     589             : "    int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
     590             : "sMonth=0, sYear=0;\n"
     591             : "    int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
     592             : "    int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
     593             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
     594             : "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     595             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
     596             : "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     597             : "    rYear= sYear;\n"
     598             : "    nSettle=nSettle+nNullDate;\n"
     599             : "    aDate=DateToDays( rDay,rMonth,rYear );\n"
     600             : "    if( aDate < nSettle )\n"
     601             : "    {\n"
     602             : "        rYear+= 1;\n"
     603             : "        aDate=DateToDays( rDay,rMonth,rYear );\n"
     604             : "    }\n"
     605             : "    while(aDate > nSettle )\n"
     606             : "    {\n"
     607             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
     608             : ");\n"
     609             : "        aDate=DateToDays( rDay,rMonth,rYear );\n"
     610             : "    }\n"
     611             : "    return getDiff( aDate, nSettle, rDay, rMonth, rYear, rbLastDayMode, "
     612             : "rbLastDay, rb30Days, rbUSMode, rnDay, sDay, sMonth, sYear, sbLastDayMode,"
     613             : "sbLastDay, sb30Days, sbUSMode, snDay);\n"
     614             : "}\n";
     615             : 
     616           0 : std::string lcl_Getcoupdaybs_newDecl=
     617             : "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
     618             : "int nBase);\n";
     619             : 
     620           0 : std::string lcl_Getcoupdaybs_new=
     621             : "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq,"
     622             : "int nBase)\n"
     623             : "{\n"
     624             : "    int aDate = nMat;\n"
     625             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     626             : "rbUSMode=0,rnDay=0;\n"
     627             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     628             : "sbUSMode=0,snDay=0;\n"
     629             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     630             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     631             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     632             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     633             : "    rYear=sYear;\n"
     634             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     635             : "    aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
     636             : "    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
     637             : "sbLastDay,rDay,sDay))\n"
     638             : "    {\n"
     639             : "        rYear+=1;\n"
     640             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     641             : "        aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
     642             : "    }\n"
     643             : "    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     644             : "rbLastDay,sDay,rDay))\n"
     645             : "    {\n"
     646             : "        double d = -1*(12/nFreq);\n"
     647             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
     648             : "        aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
     649             : "    }\n"
     650             : "    return getDiff( aDate,nSettle+nNullDate,rDay,rMonth,rYear,rbLastDayMode,"
     651             : "rbLastDay,rb30Days,rbUSMode,rnDay,sDay,sMonth,sYear,sbLastDayMode,sbLastDay,"
     652             : "sb30Days,sbUSMode, snDay);\n"
     653             : "}\n";
     654             : 
     655           0 : std::string lcl_GetcoupdaysDecl=
     656             : "int lcl_Getcoupdays(int nNullDate,int nSettle, "
     657             : "int nMat,int nFreq,int nBase);\n";
     658             : 
     659           0 : std::string lcl_Getcoupdays=
     660             : "int lcl_Getcoupdays(int nNullDate,int nSettle, "
     661             : "int nMat,int nFreq,int nBase)\n"
     662             : "{\n"
     663             : "    int aDate = nMat;\n"
     664             : "    int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
     665             : "sMonth=0, sYear=0;\n"
     666             : "    int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
     667             : "    int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
     668             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
     669             : "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     670             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,&"
     671             : "sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     672             : "    rYear= sYear;\n"
     673             : "    nSettle=nSettle+nNullDate;\n"
     674             : "    aDate=DateToDays( rDay,rMonth,rYear );\n"
     675             : "    if( aDate < nSettle )\n"
     676             : "    {  \n"
     677             : "        rYear+= 1;\n"
     678             : "        aDate=DateToDays( rDay,rMonth,rYear );\n"
     679             : "    }\n"
     680             : "    while(aDate > nSettle )\n"
     681             : "    {\n"
     682             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,-1*(12/nFreq),&rYear"
     683             : ");\n"
     684             : "        aDate=DateToDays( rDay,rMonth,rYear );\n"
     685             : "    }\n"
     686             : "    int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
     687             : "    int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
     688             : "abUSMode=rbUSMode,anDay=rnDay;\n"
     689             : "    addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,12/nFreq,&aYear);\n"
     690             : "    return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
     691             : "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
     692             : "abLastDay, ab30Days, abUSMode, anDay);\n"
     693             : "}\n";
     694             : 
     695           0 : std::string lcl_Getcoupdays_newDecl=
     696             : "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
     697             : "int nMat,int nFreq,int nBase);\n";
     698             : 
     699           0 : std::string lcl_Getcoupdays_new=
     700             : "int lcl_Getcoupdays_new(int nNullDate,int nSettle, "
     701             : "int nMat,int nFreq,int nBase)\n"
     702             : "{\n"
     703             : "    int aDate = nMat;\n"
     704             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     705             : "rbUSMode=0,rnDay=0;\n"
     706             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     707             : "sbUSMode=0,snDay=0;\n"
     708             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     709             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     710             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     711             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     712             : "    rYear=sYear;\n"
     713             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     714             : "    aDate=DateToDays_new( rnDay,rMonth,rYear);\n"
     715             : "    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
     716             : "sbLastDay,rDay,sDay))\n"
     717             : "    {\n"
     718             : "        rYear+=1;\n"
     719             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     720             : "        aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
     721             : "    }\n"
     722             : "    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     723             : "rbLastDay,sDay,rDay))\n"
     724             : "    {\n"
     725             : "        double d = -1*12*pow((double)nFreq,-1.0);\n"
     726             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
     727             : "        aDate=DateToDays_new( rnDay,rMonth,rYear );\n"
     728             : "    }\n"
     729             : "    int aNextDate=aDate;int aDay=rDay,aMonth=rMonth, aYear=rYear;\n"
     730             : "    int abLastDayMode=rbLastDayMode, abLastDay=rbLastDay,ab30Days=rb30Days,"
     731             : "abUSMode=rbUSMode,anDay=rnDay;\n"
     732             : "    int tmp = (int)(12*pow((double)nFreq,-1.0));\n"
     733             : "    addMonths(ab30Days,abLastDay,&anDay,aDay,&aMonth,tmp,&aYear);\n"
     734             : "    return getDiff( aDate, aNextDate, rDay, rMonth, rYear, rbLastDayMode, "
     735             : "rbLastDay, rb30Days, rbUSMode, rnDay, aDay, aMonth, aYear, abLastDayMode,"
     736             : "abLastDay, ab30Days, abUSMode, anDay);\n"
     737             : "}\n";
     738             : 
     739           0 : std::string lcl_GetcoupnumDecl=
     740             : "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n";
     741             : 
     742           0 : std::string lcl_Getcoupnum=
     743             : "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n"
     744             : "{\n"
     745             : "    int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear="
     746             : "0;\n"
     747             : "    int sDay=0,sMonth=0, sYear=0;\n"
     748             : "    DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
     749             : "    DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
     750             : "    DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
     751             : "    rYear= sYear;\n"
     752             : "    nSettle=nSettle+nNullDate;\n"
     753             : "    aDate=DateToDays( rDay,rMonth,rYear );\n"
     754             : "    if( aDate < nSettle )\n"
     755             : "        rYear+= 1;\n"
     756             : "    int d=DateToDays( rDay,rMonth,rYear );\n"
     757             : "    int nMonthCount=-1*(12 / nFreq);\n"
     758             : "    while(d > nSettle )\n"
     759             : "    {\n"
     760             : "        int nNewMonth = nMonthCount + rMonth;\n"
     761             : "        if( nNewMonth > 12 )\n"
     762             : "        {\n"
     763             : "            --nNewMonth;\n"
     764             : "            rYear+=nNewMonth / 12;\n"
     765             : "            rMonth = nNewMonth % 12 + 1;\n"
     766             : "        }\n"
     767             : "        else if( nNewMonth < 1 )\n"
     768             : "        {\n"
     769             : "            rYear+= nNewMonth / 12 - 1;\n"
     770             : "            rMonth = nNewMonth % 12 + 12;\n"
     771             : "        }\n"
     772             : "        else\n"
     773             : "            rMonth =  nNewMonth;\n"
     774             : "        d=DateToDays( rDay,rMonth,rYear );\n"
     775             : "    }\n"
     776             : "    int n=(mYear-rYear)*12+mMonth-rMonth;\n"
     777             : "    n=n*nFreq/12;\n"
     778             : "    return n;\n"
     779             : "}\n";
     780           0 : std::string lcl_Getcoupnum_newDecl=
     781             : "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int"
     782             : " nBase);\n";
     783           0 : std::string lcl_Getcoupnum_new=
     784             : "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int"
     785             : " nBase)\n"
     786             : "{\n"
     787             : "    int aDate = nMat;\n"
     788             : "    int mDay=0,mMonth=0, mYear=0;\n"
     789             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     790             : "rbUSMode=0,rnDay=0;\n"
     791             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     792             : "sbUSMode=0,snDay=0;\n"
     793             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     794             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     795             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     796             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     797             : "    mMonth = rMonth, mYear = rYear;\n"
     798             : "    rYear=sYear;\n"
     799             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     800             : "    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
     801             : "sbLastDay,rDay,sDay))\n"
     802             : "    {\n"
     803             : "        rYear+=1;\n"
     804             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     805             : "    }\n"
     806             : "    int m= checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     807             : "rbLastDay,sDay,rDay);\n"
     808             : "    while(m)\n"
     809             : "    {\n"
     810             : "        double d = -1*(12/nFreq);\n"
     811             : "        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
     812             : "        m = checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     813             : "rbLastDay,sDay,rDay);\n"
     814             : "    }\n"
     815             : "    int n=(mYear-rYear)*12+mMonth-rMonth;\n"
     816             : "    double tmp = (double)(n*nFreq)/12.0;\n"
     817             : "    return tmp;\n"
     818             : "}\n";
     819             : 
     820           0 : std::string setDayDecl=
     821             : "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
     822             : "int *nDay);\n";
     823           0 : std::string setDay=
     824             : "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days,"
     825             : "int *nDay)\n"
     826             : "{\n"
     827             : "    if( b30Days )\n"
     828             : "    {\n"
     829             : "        *nDay = min( nOrigDay, 30);\n"
     830             : "        if( bLastDay || (*nDay >= DaysInMonth( nMonth, nYear )) )\n"
     831             : "            *nDay = 30;\n"
     832             : "    }\n"
     833             : "    else\n"
     834             : "    {\n"
     835             : "        int nLastDay = DaysInMonth( nMonth, nYear );\n"
     836             : "        *nDay = bLastDay ? nLastDay : min( nOrigDay, nLastDay );\n"
     837             : "    }\n"
     838             : "}\n";
     839             : 
     840             : 
     841           0 : std::string coupdaysDecl=
     842             : "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n";
     843             : 
     844             : 
     845           0 : std::string coupdays=
     846             : "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n"
     847             : "{\n"
     848             : "    int nNullDate=GetNullDate();\n"
     849             : "    if( nBase == 1 )\n"
     850             : "        return lcl_Getcoupdays(nNullDate, nSettle, nMat,nFreq, nBase);\n"
     851             : "    else\n"
     852             : "        return (double)GetDaysInYear(0,0,nBase)/nFreq;\n"
     853             : "}\n";
     854           0 : std::string coupdays_newDecl=
     855             : "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n";
     856             : 
     857           0 : std::string coupdays_new=
     858             : "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n"
     859             : "{\n"
     860             : "    int nNullDate=693594;\n"
     861             : "    if( nBase == 1 )\n"
     862             : "        return lcl_Getcoupdays_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
     863             : "    else\n"
     864             : "        return (double)GetDaysInYear(0,0,nBase)*pow((double)nFreq,-1.0);\n"
     865             : "}\n";
     866             : 
     867           0 : std::string coupdaybsDecl=
     868             : "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n";
     869             : 
     870           0 : std::string coupdaybs=
     871             : "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n"
     872             : "{\n"
     873             : "    int nNullDate=GetNullDate();\n"
     874             : "    return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n"
     875             : "}\n";
     876             : 
     877           0 : std::string coupdaybs_newDecl=
     878             : "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n";
     879             : 
     880           0 : std::string coupdaybs_new=
     881             : "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n"
     882             : "{\n"
     883             : "    int nNullDate=693594;\n"
     884             : "    return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n"
     885             : "}\n";
     886             : 
     887           0 : std::string coupdaysncDecl=
     888             : "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n";
     889             : 
     890             : 
     891           0 : std::string coupdaysnc=
     892             :     "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n"
     893             : "{\n"
     894             : "    int nNullDate=GetNullDate();\n"
     895             : "    if((nBase != 0) && (nBase != 4))\n"
     896             : "    {\n"
     897             : "        int aDate = nMat;\n"
     898             : "        int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=0;int sDay=0,"
     899             : "sMonth=0, sYear=0;\n"
     900             : "        int rbLastDayMode=0, rbLastDay=0,rb30Days=0,rbUSMode=0,rnDay=0;\n"
     901             : "        int sbLastDayMode=0, sbLastDay=0,sb30Days=0,sbUSMode=0,snDay=0;\n"
     902             : "        ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,&"
     903             : "rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     904             : "        ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     905             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     906             : "        rYear= sYear;\n"
     907             : "        nSettle=nSettle+nNullDate;\n"
     908             : "        aDate=DateToDays( rDay,rMonth,rYear );\n"
     909             : "        if( aDate > nSettle )\n"
     910             : "        {\n"
     911             : "            rYear-= 1;\n"
     912             : "            aDate=DateToDays( rDay,rMonth,rYear );\n"
     913             : "        }\n"
     914             : "        while(aDate <= nSettle )\n"
     915             : "        {\n"
     916             : "            addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear)"
     917             : ";\n"
     918             : "            aDate=DateToDays( rDay,rMonth,rYear );\n"
     919             : "        }\n"
     920             : "        return getDiff( nSettle, aDate, sDay, sMonth, sYear, sbLastDayMode, "
     921             : "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
     922             : "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
     923             : "    }\n"
     924             : "    else\n"
     925             : "        return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat,"
     926             : "nFreq,nBase);\n"
     927             : "}\n";
     928           0 : std::string coupdaysnc_newDecl=
     929             : "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n";
     930             : 
     931           0 : std::string coupdaysnc_new=
     932             : "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n"
     933             : "{\n"
     934             : "    int nNullDate=693594;\n"
     935             : "    if((nBase != 0) && (nBase != 4))\n"
     936             : "    {\n"
     937             : "    int aDate = nMat;\n"
     938             : "    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
     939             : "rbUSMode=0,rnDay=0;\n"
     940             : "    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
     941             : "sbUSMode=0,snDay=0;\n"
     942             : "    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
     943             : "&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
     944             : "    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
     945             : "&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
     946             : "    rYear=sYear;\n"
     947             : "    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     948             : "    aDate=DateToDays( rnDay,rMonth,rYear);\n"
     949             : "    if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
     950             : ",sDay,rDay))\n"
     951             : "    {\n"
     952             : "        rYear-=1;\n"
     953             : "        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
     954             : "        aDate=DateToDays( rnDay,rMonth,rYear );\n"
     955             : "    }\n"
     956             : "    while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
     957             : "rbLastDay,sDay,rDay))\n"
     958             : "    {\n"
     959             : "      addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
     960             : "      aDate=DateToDays( rnDay,rMonth,rYear );\n"
     961             : "    }\n"
     962             : "    return getDiff( nSettle+nNullDate,aDate,sDay,sMonth,sYear,sbLastDayMode, "
     963             : "sbLastDay, sb30Days, sbUSMode, snDay, rDay, rMonth, rYear, rbLastDayMode, "
     964             : "rbLastDay, rb30Days, rbUSMode, rnDay);\n"
     965             : "    }\n"
     966             : "    else\n"
     967             : "        return coupdays_new(nSettle,nMat,nFreq,nBase)- coupdaybs_new( nSettle,"
     968             : "nMat,nFreq,nBase);\n"
     969             : "}\n";
     970             : 
     971           0 : std::string checklessthanDecl=
     972             : "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
     973             : "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n";
     974           0 : std::string checklessthan=
     975             : "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int "
     976             : "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n"
     977             : "{\n"
     978             : "    if( aYear != bYear )\n"
     979             : "        return aYear < bYear;\n"
     980             : "    if( aMonth != bMonth )\n"
     981             : "        return aMonth < bMonth;\n"
     982             : "    if( anDay != bnDay )\n"
     983             : "        return anDay < bnDay;\n"
     984             : "    if( abLastDay || bbLastDay )\n"
     985             : "        return !abLastDay && bbLastDay;\n"
     986             : "    return anOrigDay < bnOrigDay;\n"
     987             : "}\n";
     988             : 
     989           0 : std::string coupnumDecl=
     990             : "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n";
     991             : 
     992           0 : std::string coupnum=
     993             : "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n"
     994             : "{\n"
     995             : "    int nNullDate=GetNullDate();\n"
     996             : "    return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
     997             : "}\n";
     998           0 : std::string coupnum_newDecl=
     999             : "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n";
    1000             : 
    1001           0 : std::string coupnum_new=
    1002             : "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n"
    1003             : "{\n"
    1004             : "    int nNullDate=693594;\n"
    1005             : "    return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n"
    1006             : "}\n";
    1007             : 
    1008           0 : std::string getPrice_Decl=
    1009             : "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
    1010             :     "double fRedemp, int nFreq, int nBase );\n";
    1011             : 
    1012             : 
    1013           0 : std::string getPrice_=
    1014             : "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
    1015             :     "double fRedemp, int nFreq, int nBase )\n"
    1016             : "{\n"
    1017             : "    double      fFreq = nFreq;\n"
    1018             : "    double      fE = coupdays( nSettle, nMat, nFreq, nBase );\n"
    1019             : "    double      fDSC_E = coupdaysnc(  nSettle, nMat, nFreq, nBase ) / fE;\n"
    1020             : "    double      fN = coupnum( nSettle, nMat, nFreq, nBase );\n"
    1021             : "    double      fA = coupdaybs( nSettle, nMat, nFreq, nBase );\n"
    1022             : "    double      fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
    1023             : "fDSC_E ) );\n"
    1024             : "    fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
    1025             : "    double      fT1 = 100.0 * fRate / fFreq;\n"
    1026             : "    double      fT2 = 1.0 + fYield / fFreq;\n"
    1027             : "    for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
    1028             : "        fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
    1029             : "    return fRet;\n"
    1030             : "}\n";
    1031           0 : std::string getPrice_new_Decl=
    1032             : "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
    1033             :     "double fRedemp, int nFreq, int nBase );\n";
    1034             : 
    1035             : 
    1036           0 : std::string getPrice_new=
    1037             : "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n"
    1038             :     "double fRedemp, int nFreq, int nBase )\n"
    1039             : "{\n"
    1040             : "    double      fFreq = nFreq;\n"
    1041             : "    double      fE = coupdays_new( nSettle, nMat, nFreq, nBase );\n"
    1042             : "    double      fDSC_E = coupdaysnc_new(  nSettle, nMat, nFreq, nBase ) / fE;\n"
    1043             : "    double      fN = coupnum_new( nSettle, nMat, nFreq, nBase );\n"
    1044             : "    double      fA = coupdaybs_new( nSettle, nMat, nFreq, nBase );\n"
    1045             : "    double      fRet = fRedemp / ( pow( 1.0 + fYield / fFreq, fN - 1.0 + "
    1046             : "fDSC_E ) );\n"
    1047             : "    fRet -= 100.0 * fRate / fFreq * fA / fE;\n"
    1048             : "    double      fT1 = 100.0 * fRate / fFreq;\n"
    1049             : "    double      fT2 = 1.0 + fYield / fFreq;\n"
    1050             : "    for( double fK = 0.0 ; fK < fN ; fK+=1.0 )\n"
    1051             : "        fRet += fT1 / pow( fT2, fK + fDSC_E );\n"
    1052             : "    return fRet;\n"
    1053             : "}\n";
    1054             : 
    1055           0 : std::string getYield_Decl=
    1056             : "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
    1057             : "double fPrice,double fRedemp, int nFreq, int nBase);\n";
    1058             : 
    1059           0 : std::string getYield_=
    1060             : "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup,"
    1061             : "double fPrice,double fRedemp, int nFreq, int nBase )\n"
    1062             : "{\n"
    1063             : "    double      fRate = fCoup;\n"
    1064             : "    double      fPriceN = 0.0;\n"
    1065             : "    double      fYield1 = 0.0;\n"
    1066             : "    double      fYield2 = 1.0;\n"
    1067             : "    double      fPrice1 = getPrice_(nSettle, nMat, fRate, fYield1, fRedemp, "
    1068             : "nFreq, nBase );\n"
    1069             : "    double      fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, "
    1070             : "nFreq, nBase );\n"
    1071             : "    double      fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
    1072             : "    for( unsigned int nIter = 0 ; nIter < 100 && fPriceN != fPrice ; nIter++ "
    1073             : ")\n"
    1074             : "    {\n"
    1075             : "        fPriceN = getPrice_(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, "
    1076             : "nBase );\n"
    1077             : "        if( fPrice == fPrice1 )\n"
    1078             : "            return fYield1;\n"
    1079             : "        else if( fPrice == fPrice2 )\n"
    1080             : "            return fYield2;\n"
    1081             : "        else if( fPrice == fPriceN )\n"
    1082             : "            return fYieldN;\n"
    1083             : "        else if( fPrice < fPrice2 )\n"
    1084             : "        {\n"
    1085             : "            fYield2 *= 2.0;\n"
    1086             : "            fPrice2 = getPrice_(nSettle, nMat, fRate, fYield2, fRedemp, nFreq"
    1087             : ", nBase );\n"
    1088             : "            fYieldN = ( fYield2 - fYield1 ) * 0.5;\n"
    1089             : "        }\n"
    1090             : "        else\n"
    1091             : "        {\n"
    1092             : "            if( fPrice < fPriceN )\n"
    1093             : "            {\n"
    1094             : "                fYield1 = fYieldN;\n"
    1095             : "                fPrice1 = fPriceN;\n"
    1096             : "            }\n"
    1097             : "            else\n"
    1098             : "            {\n"
    1099             : "                fYield2 = fYieldN;\n"
    1100             : "                fPrice2 = fPriceN;\n"
    1101             : "            }\n"
    1102             : "            fYieldN = fYield2 - ( fYield2 - fYield1 ) * ( ( fPrice - fPrice2 "
    1103             : ") / ( fPrice1 - fPrice2 ) );\n"
    1104             : "        }\n"
    1105             : "    }\n"
    1106             : "    return fYieldN;\n"
    1107             : "}\n";
    1108             : 
    1109           0 : std::string GetYearFracDecl=
    1110             : "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
    1111             : "int nMode );\n";
    1112             : 
    1113           0 : std::string GetYearFrac=
    1114             : "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate,"
    1115             : "int nMode ) \n"
    1116             : "{\n"
    1117             : "    if( nStartDate == nEndDate )\n"
    1118             : "        return 0.0;     \n"
    1119             : 
    1120             :  "   if( nStartDate > nEndDate )\n"
    1121             :  "   {\n"
    1122             :  "       int   n = nEndDate;\n"
    1123             :  "       nEndDate = nStartDate;\n"
    1124             :  "       nStartDate = n;\n"
    1125             :  "   }\n"
    1126             : 
    1127             :   "  int nDate1 = nStartDate + nNullDate;\n"
    1128             :   "  int nDate2 = nEndDate + nNullDate;\n"
    1129             : 
    1130             :   "  int  nDay1, nDay2;\n"
    1131             :   "  int  nMonth1, nMonth2;\n"
    1132             :   "  int  nYear1, nYear2;\n"
    1133             : 
    1134             :   "  DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
    1135             :   "  DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
    1136             : 
    1137             :   "  int nDayDiff;\n"
    1138             :   "  switch( nMode )\n"
    1139             :   "  {\n"
    1140             :   "      case 0:         \n"
    1141             :   "          if ( nDay1 == 31 )\n"
    1142             :   "          {\n"
    1143             :   "              nDay1--;\n"
    1144             :   "          }\n"
    1145             :   "          if ( nDay1 == 30 && nDay2 == 31 )\n"
    1146             :   "          {\n"
    1147             :   "              nDay2--;\n"
    1148             :   "          }\n"
    1149             :   "          else\n"
    1150             :   "          {\n"
    1151             :   "              if ( nMonth1 == 2 && nDay1 == "
    1152             :   "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
    1153             :   "              {\n"
    1154             :   "                  nDay1 = 30;\n"
    1155             :   "                  if ( nMonth2 == 2 && nDay2 == "
    1156             :   "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
    1157             :   "                  {\n"
    1158             :   "                      nDay2 = 30;\n"
    1159             :   "                  }\n"
    1160             :   "              }\n"
    1161             :   "          }\n"
    1162             :   "          nDayDiff = ( nYear2 - nYear1 ) * 360 + "
    1163             :   "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
    1164             :   "          break;\n"
    1165             :   "      case 1:         \n"
    1166             :   "      case 2:        \n"
    1167             :   "      case 3:         \n"
    1168             :   "         nDayDiff = nDate2 - nDate1;\n"
    1169             :   "          break;\n"
    1170             :   "      case 4:         \n"
    1171             :   "          if ( nDay1 == 31 )\n"
    1172             :   "          {\n"
    1173             :   "              nDay1--;\n"
    1174             :   "          }\n"
    1175             :   "          if ( nDay2 == 31 )\n"
    1176             :   "          {\n"
    1177             :   "              nDay2--;\n"
    1178             :   "          }\n"
    1179             :   "          nDayDiff = ( nYear2 - nYear1 ) * 360 + "
    1180             :   "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
    1181             :   "          break;\n"
    1182             :   "  }\n"
    1183             : 
    1184             :   "  double nDaysInYear;\n"
    1185             :   "  switch( nMode )\n"
    1186             :   "  {\n"
    1187             :   "      case 0:         \n"
    1188             :   "      case 2:         \n"
    1189             :   "      case 4:         \n"
    1190             :   "          nDaysInYear = 360;\n"
    1191             :   "          break;\n"
    1192             :   "      case 1:         \n"
    1193             :   "          {\n"
    1194             :   "              bool isYearDifferent = ( nYear1 != nYear2 );\n"
    1195             :   "              if ( isYearDifferent &&\n"
    1196             :   "                   ( ( nYear2 != nYear1 + 1 ) ||\n"
    1197             :   "                     ( nMonth1 < nMonth2 ) ||\n"
    1198             :   "                     ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
    1199             :   "              {\n"
    1200             : 
    1201             :   "                  int nDayCount = 0;\n"
    1202             :   "                 for ( int i = nYear1; i <= nYear2; i++ )\n"
    1203             :   "                      nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
    1204             : 
    1205             :   "                  nDaysInYear = ( double ) nDayCount / "
    1206             :   "( double ) ( nYear2 - nYear1 + 1 );\n"
    1207             :   "              }\n"
    1208             :   "             else\n"
    1209             :   "              {\n"
    1210             :   "                  if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
    1211             :   "                  {\n"
    1212             :   "                      nDaysInYear = 366;\n"
    1213             :   "                  }\n"
    1214             :   "                   else\n"
    1215             :   "                  {\n"
    1216             : 
    1217             :   "                      if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
    1218             :   "&& nDay1 <= 29 ) ||\n"
    1219             :   "                           ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
    1220             :   "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
    1221             :    "                     {\n"
    1222             :    "                         nDaysInYear = 366;\n"
    1223             :    "                     }\n"
    1224             :   "                      else\n"
    1225             :   "                      {\n"
    1226             :   "                          nDaysInYear = 365;\n"
    1227             :  "                           for ( int i = nYear1; i <= nYear2; i++ )\n"
    1228             :   "                          {\n"
    1229             :    "                             if ( IsLeapYear( i ) )\n"
    1230             :   "                              {\n"
    1231             :   "                                  nDaysInYear = 366;\n"
    1232             :    "                                 break;\n"
    1233             :    "                             }\n"
    1234             :   "                          }\n"
    1235             :    "                     }\n"
    1236             :    "                 }\n"
    1237             :    "             }\n"
    1238             :    "         }\n"
    1239             :   "          break;\n"
    1240             :   "      case 3:         \n"
    1241             :   "          nDaysInYear = 365;\n"
    1242             :  "           break;\n"
    1243             :   "  }\n"
    1244             :   "  return (double)( nDayDiff ) / (nDaysInYear);\n"
    1245             : "}\n";
    1246             : 
    1247             : 
    1248           0 : std::string GetYieldmatDecl=
    1249             :     "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
    1250             :         "double fRate, double fPrice, int nBase );\n";
    1251             : 
    1252             : 
    1253           0 : std::string GetYieldmat=
    1254             :     "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n"
    1255             :         "double fRate, double fPrice, int nBase )\n"
    1256             : "{\n"
    1257             : "    double      fIssMat = GetYearFrac_new( nNullDate, nIssue, nMat, nBase );\n"
    1258             : "    double      fIssSet = GetYearFrac_new( nNullDate, nIssue, nSettle, nBase );\n"
    1259             : "    double      fSetMat = GetYearFrac_new( nNullDate, nSettle, nMat, nBase );\n"
    1260             : "    double      y = 1.0 + fIssMat * fRate;\n"
    1261             : "    y =y * pow( (fPrice / 100.0 + fIssSet * fRate),-1);\n"
    1262             : "    y-=1.0;\n"
    1263             : "    y = y * pow(fSetMat,-1);\n"
    1264             : "    return y;\n"
    1265             : "}\n";
    1266             : 
    1267           0 : std::string GetDiffDateDecl=
    1268             : "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
    1269             : "    int* pOptDaysIn1stYear );\n";
    1270             : 
    1271           0 : std::string GetDiffDate=
    1272             : "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode,"
    1273             : "    int* pOptDaysIn1stYear )\n"
    1274             : "{\n"
    1275             : "    bool    bNeg = nStartDate > nEndDate;\n"
    1276             : "    if( bNeg )\n"
    1277             : "    {\n"
    1278             : "        int   n = nEndDate;\n"
    1279             : "        nEndDate = nStartDate;\n"
    1280             : "        nStartDate = n;\n"
    1281             : "    }\n"
    1282             : "    int       nRet;\n"
    1283             : "    switch( nMode )\n"
    1284             : "    {\n"
    1285             : "    case 0:   \n"
    1286             : "    case 4:   \n"
    1287             : "        {\n"
    1288             : "        int      nD1, nM1, nY1, nD2, nM2, nY2;\n"
    1289             : "        nStartDate += nNullDate;\n"
    1290             : "        nEndDate += nNullDate;\n"
    1291             : "        DaysToDate( nStartDate, &nD1, &nM1, &nY1 );\n"
    1292             : "        DaysToDate( nEndDate, &nD2, &nM2, &nY2 );\n"
    1293             : "        bool        bLeap = IsLeapYear( nY1 );\n"
    1294             : "        int       nDays, nMonths;\n"
    1295             : "        nMonths = nM2 - nM1;\n"
    1296             : "        nDays = nD2 - nD1;\n"
    1297             : "        nMonths += ( nY2 - nY1 ) * 12;\n"
    1298             : "        nRet = nMonths * 30 + nDays;\n"
    1299             : "        if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
    1300             : "            nRet -= bLeap? 1 : 2;\n"
    1301             : "        if( pOptDaysIn1stYear )\n"
    1302             : "            *pOptDaysIn1stYear = 360;\n"
    1303             : "        }\n"
    1304             : "        break;\n"
    1305             : "    case 1:    \n"
    1306             : "        if( pOptDaysIn1stYear )\n"
    1307             : "        {\n"
    1308             : "            int      nD, nM, nY;\n"
    1309             : "            DaysToDate( nStartDate + nNullDate, &nD, &nM, &nY );\n"
    1310             : "            *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
    1311             : "        }\n"
    1312             : "        nRet = nEndDate - nStartDate;\n"
    1313             : "        break;\n"
    1314             : "    case 2:      \n"
    1315             : "        nRet = nEndDate - nStartDate;\n"
    1316             : "        if( pOptDaysIn1stYear )\n"
    1317             : "            *pOptDaysIn1stYear = 360;\n"
    1318             : "        break;\n"
    1319             : "    case 3:        \n"
    1320             : "        nRet = nEndDate - nStartDate;\n"
    1321             : "        if( pOptDaysIn1stYear )\n"
    1322             : "            *pOptDaysIn1stYear = 365;\n"
    1323             : "        break;\n"
    1324             : "    }\n"
    1325             : "    return bNeg? -nRet : nRet;\n"
    1326             : "}\n";
    1327             : 
    1328           0 : std::string GetYearDiffDecl=
    1329             : "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
    1330             : "int nMode);\n";
    1331             : 
    1332           0 : std::string GetYearDiff=
    1333             : "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate,"
    1334             : "int nMode )\n"
    1335             : "{\n"
    1336             : "    int   nDays1stYear;\n"
    1337             : "    int   nTotalDays = GetDiffDate( nNullDate, nStartDate, nEndDate,"
    1338             : "nMode, &"
    1339             : "nDays1stYear );\n"
    1340             : "     return (double)(nTotalDays)*pow((double)nDays1stYear,-1);\n"
    1341             : "}\n";
    1342             : 
    1343           0 : std::string GetDiffDate360_Decl=
    1344             : "int GetDiffDate360_(\n"
    1345             : "                int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
    1346             : "                int nDay2, int nMonth2, int nYear2,\n"
    1347             : "                bool bUSAMethod );\n";
    1348             : 
    1349           0 : std::string GetDiffDate360_=
    1350             : "int GetDiffDate360_(\n"
    1351             : "                int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n"
    1352             : "                int nDay2, int nMonth2, int nYear2,\n"
    1353             : "                bool bUSAMethod )\n"
    1354             : "{\n"
    1355             : "    if( nDay1 == 31 )\n"
    1356             : "        nDay1--;\n"
    1357             : "    else if( bUSAMethod && ( nMonth1 == 2 && ( nDay1 == 29 || ( nDay1 == 28 "
    1358             : "&& !bLeapYear1 ) ) ) )\n"
    1359             : "        nDay1 = 30;\n"
    1360             : "    if( nDay2 == 31 )\n"
    1361             : "    {\n"
    1362             : "        if( bUSAMethod && nDay1 != 30 )\n"
    1363             : "        {\n"
    1364             : "            nDay2 = 1;\n"
    1365             : "            if( nMonth2 == 12 )\n"
    1366             : "            {\n"
    1367             : "                nYear2++;\n"
    1368             : "                nMonth2 = 1;\n"
    1369             : "            }\n"
    1370             : "            else\n"
    1371             : "                nMonth2++;\n"
    1372             : "        }\n"
    1373             : "        else\n"
    1374             : "            nDay2 = 30;\n"
    1375             : "    }\n"
    1376             : "    return nDay2 + nMonth2 * 30 + nYear2 * 360 - nDay1 - nMonth1 * 30 - "
    1377             : "nYear1 * 360;\n"
    1378             : "}\n";
    1379             : 
    1380           0 : std::string GetDiffDate360Decl=
    1381             : "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
    1382             : "bool bUSAMethod);\n";
    1383             : 
    1384             : 
    1385           0 : std::string GetDiffDate360=
    1386             : "int GetDiffDate360( int nNullDate, int nDate1, int nDate2,"
    1387             : "bool bUSAMethod )\n"
    1388             : "{\n"
    1389             : "    nDate1 += nNullDate;\n"
    1390             : "    nDate2 += nNullDate;\n"
    1391             : "    int nDay1, nMonth1, nYear1, nDay2, nMonth2, nYear2;\n"
    1392             : "    DaysToDate( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
    1393             : "    DaysToDate( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
    1394             : "    return GetDiffDate360_( nDay1, nMonth1, nYear1, IsLeapYear( nYear1 ), "
    1395             : "nDay2, nMonth2, nYear2, bUSAMethod );\n"
    1396             : "}\n";
    1397             : 
    1398           0 : std::string GetDurationDecl=
    1399             : "double GetDuration( \n"
    1400             : "                int nNullDate, int nSettle, int nMat, double fCoup,\n"
    1401             : "                double fYield, int nFreq, int nBase );\n";
    1402             : 
    1403           0 : std::string GetDuration=
    1404             : "double GetDuration( \n"
    1405             : "                int nNullDate, int nSettle, int nMat, double fCoup,\n"
    1406             : "                double fYield, int nFreq, int nBase )\n"
    1407             : "{\n"
    1408             : "    double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
    1409             : "    double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
    1410             : "    double fDur = 0.0;\n"
    1411             : "    double f100 = 100.0;\n"
    1412             : "    fCoup *= f100 / nFreq;\n"
    1413             : "    fYield /= nFreq;\n"
    1414             : "    fYield += 1.0;\n"
    1415             : "    double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
    1416             : "    int  t;\n"
    1417             : "    for( t = 1 ; t < fNumOfCoups ; t++ )\n"
    1418             : "        fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
    1419             : "    fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
    1420             : " pow( fYield, fNumOfCoups + nDiff );\n"
    1421             : "    double  p = 0.0;\n"
    1422             : "    for( t = 1 ; t < fNumOfCoups ; t++ )\n"
    1423             : "      p += fCoup / pow( fYield, t + nDiff );\n"
    1424             : "    p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
    1425             : "    fDur /= p;\n"
    1426             : "    fDur /= nFreq;\n"
    1427             : "    return fDur;\n""}\n";
    1428             : 
    1429           0 : std::string GetDuration_newDecl=
    1430             : "double GetDuration_new( \n"
    1431             : "                int nNullDate, int nSettle, int nMat, double fCoup,\n"
    1432             : "                double fYield, int nFreq, int nBase );\n";
    1433             : 
    1434           0 : std::string GetDuration_new=
    1435             : "double GetDuration_new( \n"
    1436             : "                int nNullDate, int nSettle, int nMat, double fCoup,\n"
    1437             : "                double fYield, int nFreq, int nBase )\n"
    1438             : "    {\n"
    1439             : "        double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
    1440             : "        double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
    1441             : "nFreq,nBase);\n"
    1442             : "        double fDur = 0.0;\n"
    1443             : "        fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
    1444             : "        fYield = fYield * pow(nFreq, -1.0);\n"
    1445             : "        fYield += 1.0;\n"
    1446             : "        double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
    1447             : "        int  t;\n"
    1448             : "        double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
    1449             : "        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
    1450             : "            tmp0 = (t + nDiff) * ( fCoup ) ;\n"
    1451             : "            tmp1 = pow( fYield, t + nDiff ) ;\n"
    1452             : "            tmp2 = tmp0 * pow(tmp1, -1);\n"
    1453             : "            fDur += tmp2;\n"
    1454             : "        }\n"
    1455             : "        fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
    1456             : " fNumOfCoups + nDiff ),-1);\n"
    1457             : "        double  p = 0.0;\n"
    1458             : "        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
    1459             : "            tmp0 = pow( fYield, t + nDiff );\n"
    1460             : "            p += fCoup * pow(tmp0, -1);}\n"
    1461             : "        p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
    1462             : "        fDur = fDur * pow(p, -1.0);\n"
    1463             : "        fDur = fDur * pow(nFreq, -1.0);\n"
    1464             : "        return fDur;\n"
    1465             : "    }\n";
    1466             : 
    1467           0 : std::string ScGetGDADecl=
    1468             : "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
    1469             : "double fFaktor);\n";
    1470             : 
    1471           0 : std::string ScGetGDA=
    1472             : "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
    1473             : "double fFaktor)\n"
    1474             : "{\n"
    1475             : "    double fGda, fZins, fAlterWert, fNeuerWert;\n"
    1476             : "    fZins = fFaktor / fDauer;\n"
    1477             : "    if (fZins >= 1.0)\n"
    1478             : "    {\n"
    1479             : "        fZins = 1.0;\n"
    1480             : "        if (fPeriode == 1.0)\n"
    1481             : "            fAlterWert = fWert;\n"
    1482             : "        else\n"
    1483             : "            fAlterWert = 0.0;\n"
    1484             : "    }\n"
    1485             : "    else\n"
    1486             : "        fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"
    1487             : "    fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"
    1488             : 
    1489             : "    if (fNeuerWert < fRest)\n"
    1490             : "        fGda = fAlterWert - fRest;\n"
    1491             : "    else\n"
    1492             : "        fGda = fAlterWert - fNeuerWert;\n"
    1493             : "    if (fGda < 0.0)\n"
    1494             : "        fGda = 0.0;\n"
    1495             : "    return fGda;\n"
    1496             : "}\n";
    1497             : 
    1498           0 : std::string DblMinDecl=
    1499             : "inline double DblMin( double a, double b );\n";
    1500             : 
    1501           0 : std::string DblMin=
    1502             : "inline double DblMin( double a, double b )\n"
    1503             : "{\n"
    1504             : "    return (a < b) ? a : b;\n"
    1505             : "}\n";
    1506             : 
    1507           0 : std::string ScInterVDBDecl=
    1508             : "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
    1509             : "double fPeriode,double fFaktor);\n";
    1510             : 
    1511           0 : std::string ScInterVDB=
    1512             : "double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
    1513             : "double fPeriode,double fFaktor)\n"
    1514             : "{\n"
    1515             : "    double fVdb=0;\n"
    1516             : "    double fIntEnd   = ceil(fPeriode);\n"
    1517             : "    int nLoopEnd   = fIntEnd;\n"
    1518             : 
    1519             : "    double fTerm, fLia;\n"
    1520             : "    double fRestwert = fWert - fRest;\n"
    1521             : "    int bNowLia = 0;\n"
    1522             : "    double fGda;\n"
    1523             : "    int i;\n"
    1524             : "    fLia=0;\n"
    1525             : "    for ( i = 1; i <= nLoopEnd; i++)\n"
    1526             : "    {\n"
    1527             : "        if(!bNowLia)\n"
    1528             : "        {\n"
    1529             : "            fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
    1530             : "            fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
    1531             : "            if (fLia > fGda)\n"
    1532             : "            {\n"
    1533             : "                fTerm = fLia;\n"
    1534             : "                bNowLia = 1;\n"
    1535             : "            }\n"
    1536             : "            else\n"
    1537             : "            {\n"
    1538             : "                fTerm = fGda;\n"
    1539             : "                fRestwert =fRestwert- fGda;\n"
    1540             : "            }\n"
    1541             : "        }\n"
    1542             : "        else\n"
    1543             : "        {\n"
    1544             : "            fTerm = fLia;\n"
    1545             : "        }\n"
    1546             : 
    1547             : "        if ( i == nLoopEnd)\n"
    1548             : "            fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
    1549             : 
    1550             : "        fVdb += fTerm;\n"
    1551             : "    }\n"
    1552             : "    return fVdb;\n"
    1553             : "}\n";
    1554             : 
    1555           0 : std::string VDBImplementDecl=
    1556             : "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
    1557             : ", double fEnde, double fFaktor,int bFlag);\n";
    1558             : 
    1559           0 : std::string VDBImplement=
    1560             : "double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
    1561             : ", double fEnde, double fFaktor,int bFlag)\n"
    1562             : "{\n"
    1563             : "    double result=0;\n"
    1564             : "    double fIntStart = floor(fAnfang);\n"
    1565             : "    double fIntEnd   = ceil(fEnde);\n"
    1566             : "    int nLoopStart = (int) fIntStart;\n"
    1567             : "    int nLoopEnd   = (int) fIntEnd;\n"
    1568             : "    if (bFlag)\n"
    1569             : "    {\n"
    1570             : "        for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
    1571             : "        {\n"
    1572             : "            double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
    1573             : ");\n"
    1574             : "            if ( i == nLoopStart+1 )\n"
    1575             : "                fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n"
    1576             : "            else if ( i == nLoopEnd )\n"
    1577             : "                fTerm *= ( fEnde + 1.0 - fIntEnd );\n"
    1578             : "            result += fTerm;\n"
    1579             : "        }\n"
    1580             : "    }\n"
    1581             : "    else\n"
    1582             : "    {\n"
    1583             : "        double fDauer1=fDauer;\n"
    1584             : "        if(!isequal(fAnfang,floor(fAnfang)))\n"
    1585             : "        {\n"
    1586             : "            if(fFaktor>1)\n"
    1587             : "            {\n"
    1588             : "                if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
    1589             : "                {\n"
    1590             : "                    double fPart=fAnfang-fDauer/2;\n"
    1591             : "                    fAnfang=fDauer/2;\n"
    1592             : "                    fEnde-=fPart;\n"
    1593             : "                    fDauer1+=1;\n"
    1594             : "                }\n"
    1595             : "            }\n"
    1596             : "        }\n"
    1597             : "        fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
    1598             : "        result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
    1599             : "fFaktor);\n"
    1600             : "    }\n"
    1601             : "    return result;\n"
    1602             : "}\n";
    1603             : 
    1604           0 : std::string GetOddlpriceDecl=
    1605             : "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
    1606             : "    double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n";
    1607             : 
    1608           0 : std::string GetOddlprice=
    1609             : "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
    1610             : "    double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n"
    1611             : "{\n"
    1612             : "    double   fFreq =  nFreq ;\n"
    1613             : "    double   fDCi = GetYearFrac( nNullDate, nLastCoup,"
    1614             : "nMat, nBase ) * fFreq;\n"
    1615             : "    double   fDSCi = GetYearFrac( nNullDate, nSettle,"
    1616             : "nMat, nBase ) * fFreq;\n"
    1617             : "    double   fAi = GetYearFrac( nNullDate, nLastCoup,"
    1618             : "nSettle, nBase ) * fFreq;\n"
    1619             : "    double   p = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
    1620             : "    p /= fDSCi * fYield / fFreq + 1.0;\n"
    1621             : "    p -= fAi * 100.0 * fRate / fFreq;\n"
    1622             : "    return p;\n"
    1623             : "}\n";
    1624             : 
    1625           0 : std::string GetOddlyieldDecl=
    1626             : "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
    1627             : "    double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
    1628             : 
    1629           0 : std::string GetOddlyield=
    1630             : "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
    1631             : "    double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
    1632             : "{\n"
    1633             : "    double fFreq =  nFreq ;\n"
    1634             : "    double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
    1635             : "    double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
    1636             : "    double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
    1637             : "    double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
    1638             : "    y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
    1639             : "    y -= 1.0;\n"
    1640             : "    y *= fFreq / fDSCi;\n"
    1641             : "    return y;\n"
    1642             : "}\n";
    1643             : 
    1644           0 : std::string GetYearFrac_newDecl=
    1645             : "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
    1646             : "int nMode );\n";
    1647             : 
    1648           0 : std::string GetYearFrac_new=
    1649             : "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate,"
    1650             : "int nMode ) \n"
    1651             : "{\n"
    1652             : "    if( nStartDate == nEndDate )\n"
    1653             : "        return 0.0;     \n"
    1654             : "   if( nStartDate > nEndDate )\n"
    1655             : "   {\n"
    1656             : "       int   n = nEndDate;\n"
    1657             : "       nEndDate = nStartDate;\n"
    1658             : "       nStartDate = n;\n"
    1659             : "   }\n"
    1660             : "  int nDate1 = nStartDate + nNullDate;\n"
    1661             : "  int nDate2 = nEndDate + nNullDate;\n"
    1662             : "  int  nDay1, nDay2;\n"
    1663             : "  int  nMonth1, nMonth2;\n"
    1664             : "  int  nYear1, nYear2;\n"
    1665             : "  DaysToDate_new( nDate1, &nDay1, &nMonth1, &nYear1 );\n"
    1666             : "  DaysToDate_new( nDate2, &nDay2, &nMonth2, &nYear2 );\n"
    1667             : "  int nDayDiff;\n"
    1668             : "  switch( nMode )\n"
    1669             : "  {\n"
    1670             : "      case 0:         \n"
    1671             : "          if ( nDay1 == 31 )\n"
    1672             : "          {\n"
    1673             : "              nDay1--;\n"
    1674             : "          }\n"
    1675             : "          if ( nDay1 == 30 && nDay2 == 31 )\n"
    1676             : "          {\n"
    1677             : "              nDay2--;\n"
    1678             : "          }\n"
    1679             : "          else\n"
    1680             : "          {\n"
    1681             : "              if ( nMonth1 == 2 && nDay1 == "
    1682             : "( IsLeapYear( nYear1 ) ? 29 : 28 ) )\n"
    1683             : "              {\n"
    1684             : "                  nDay1 = 30;\n"
    1685             : "                  if ( nMonth2 == 2 && nDay2 == "
    1686             : "( IsLeapYear( nYear2 ) ? 29 : 28 ) )\n"
    1687             : "                  {\n"
    1688             : "                      nDay2 = 30;\n"
    1689             : "                  }\n"
    1690             : "              }\n"
    1691             : "          }\n"
    1692             : "          nDayDiff = ( nYear2 - nYear1 ) * 360 + "
    1693             : "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
    1694             : "          break;\n"
    1695             : "      case 1:         \n"
    1696             : "      case 2:        \n"
    1697             : "      case 3:         \n"
    1698             : "         nDayDiff = nDate2 - nDate1;\n"
    1699             : "          break;\n"
    1700             : "      case 4:         \n"
    1701             : "          if ( nDay1 == 31 )\n"
    1702             : "          {\n"
    1703             : "              nDay1--;\n"
    1704             : "          }\n"
    1705             : "          if ( nDay2 == 31 )\n"
    1706             : "          {\n"
    1707             : "              nDay2--;\n"
    1708             : "          }\n"
    1709             : "          nDayDiff = ( nYear2 - nYear1 ) * 360 + "
    1710             : "( nMonth2 - nMonth1 ) * 30 + ( nDay2 - nDay1 );\n"
    1711             : "          break;\n"
    1712             : "  }\n"
    1713             : "  double nDaysInYear;\n"
    1714             : "  switch( nMode )\n"
    1715             : "  {\n"
    1716             : "      case 0:         \n"
    1717             : "      case 2:         \n"
    1718             : "      case 4:         \n"
    1719             : "          nDaysInYear = 360;\n"
    1720             : "          break;\n"
    1721             : "      case 1:         \n"
    1722             : "          {\n"
    1723             : "              bool isYearDifferent = ( nYear1 != nYear2 );\n"
    1724             : "              if ( isYearDifferent &&\n"
    1725             : "                   ( ( nYear2 != nYear1 + 1 ) ||\n"
    1726             : "                     ( nMonth1 < nMonth2 ) ||\n"
    1727             : "                     ( nMonth1 == nMonth2 && nDay1 < nDay2 ) ) )\n"
    1728             : "              {\n"
    1729             : "                  int nDayCount = 0;\n"
    1730             : "                 for ( int i = nYear1; i <= nYear2; i++ )\n"
    1731             : "                      nDayCount += ( IsLeapYear( i ) ? 366 : 365 );\n"
    1732             : "                  nDaysInYear = ( double ) nDayCount / "
    1733             : "( double ) ( nYear2 - nYear1 + 1 );\n"
    1734             : "              }\n"
    1735             : "             else\n"
    1736             : "              {\n"
    1737             : "                  if ( isYearDifferent && IsLeapYear( nYear1 ) )\n"
    1738             : "                  {\n"
    1739             : "                      nDaysInYear = 366;\n"
    1740             : "                  }\n"
    1741             : "                   else\n"
    1742             : "                  {\n"
    1743             : "                      if ( ( IsLeapYear( nYear1 ) && nMonth1 <= 2 "
    1744             : "&& nDay1 <= 29 ) ||\n"
    1745             : "                           ( IsLeapYear( nYear2 ) && ( nMonth2 > 3 || "
    1746             : "( nMonth2 == 2 && nDay1 == 29 ) ) ) )\n"
    1747             : "                     {\n"
    1748             : "                         nDaysInYear = 366;\n"
    1749             : "                     }\n"
    1750             : "                      else\n"
    1751             : "                      {\n"
    1752             : "                          nDaysInYear = 365;\n"
    1753             : "                           for ( int i = nYear1; i <= nYear2; i++ )\n"
    1754             : "                          {\n"
    1755             : "                             if ( IsLeapYear( i ) )\n"
    1756             : "                              {\n"
    1757             : "                                  nDaysInYear = 366;\n"
    1758             : "                                 break;\n"
    1759             : "                             }\n"
    1760             : "                          }\n"
    1761             : "                     }\n"
    1762             : "                 }\n"
    1763             : "             }\n"
    1764             : "         }\n"
    1765             : "          break;\n"
    1766             : "      case 3:         \n"
    1767             : "          nDaysInYear = 365;\n"
    1768             : "           break;\n"
    1769             : "  }\n"
    1770             : "  return (double)( nDayDiff ) / (nDaysInYear);\n"
    1771             : "}\n";
    1772             : 
    1773           0 : std::string DaysToDate_newDecl =
    1774             : "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n";
    1775             : 
    1776           0 : std::string DaysToDate_new =
    1777             : "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n"
    1778             : "{\n"
    1779             : "    int   nTempDays;\n"
    1780             : "    int   i = 0;\n"
    1781             : "    bool    bCalc;\n"
    1782             : "    do\n"
    1783             : "    {\n"
    1784             : "        nTempDays = nDays;\n"
    1785             : "        *rYear = (int)((nTempDays / 365) - i);\n"
    1786             : "        nTempDays -= ((int) *rYear -1) * 365;\n"
    1787             : "        nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
    1788             : " / 400);\n"
    1789             : "        bCalc = false;\n"
    1790             : "        if ( nTempDays < 1 )\n"
    1791             : "        {\n"
    1792             : "            i++;\n"
    1793             : "            bCalc = true;\n"
    1794             : "        }\n"
    1795             : "        else\n"
    1796             : "        {\n"
    1797             : "            if ( nTempDays > 365 )\n"
    1798             : "            {\n"
    1799             : "                if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
    1800             : "                {\n"
    1801             : "                    i--;\n"
    1802             : "                    bCalc = true;\n"
    1803             : "                }\n"
    1804             : "            }\n"
    1805             : "        }\n"
    1806             : "    }\n"
    1807             : "    while ( bCalc );\n"
    1808             : "    if(nTempDays != 0){\n"
    1809             : "        for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
    1810             : " *rMonth += 1)\n"
    1811             : "        {\n"
    1812             : "            nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
    1813             : "        }\n"
    1814             : "        *rDay = (int)nTempDays;\n"
    1815             : "    }\n"
    1816             : "}\n";
    1817             : 
    1818           0 : std::string DaysToDate_LocalBarrierDecl =
    1819             : "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n";
    1820             : 
    1821           0 : std::string DaysToDate_LocalBarrier =
    1822             : "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n"
    1823             : "{\n"
    1824             : "    int   nTempDays;\n"
    1825             : "    int   i = 0;\n"
    1826             : "    bool    bCalc;\n"
    1827             : "    do\n"
    1828             : "    {\n"
    1829             : "        nTempDays = nDays;\n"
    1830             : "        *rYear = (int)((nTempDays / 365) - i);\n"
    1831             : "        nTempDays -= ((int) *rYear -1) * 365;\n"
    1832             : "        nTempDays -= ((*rYear -1) / 4) - ((*rYear -1) / 100) + ((*rYear -1)"
    1833             : " / 400);\n"
    1834             : "        bCalc = false;\n"
    1835             : "        if ( nTempDays < 1 )\n"
    1836             : "        {\n"
    1837             : "            i++;\n"
    1838             : "            bCalc = true;\n"
    1839             : "        }\n"
    1840             : "        else\n"
    1841             : "        {\n"
    1842             : "            if ( nTempDays > 365 )\n"
    1843             : "            {\n"
    1844             : "                if ( (nTempDays != 366) || !IsLeapYear( *rYear ) )\n"
    1845             : "                {\n"
    1846             : "                    i--;\n"
    1847             : "                    bCalc = true;\n"
    1848             : "                }\n"
    1849             : "            }\n"
    1850             : "        }\n"
    1851             : "    }\n"
    1852             : "    while ( bCalc );\n"
    1853             : "    barrier(CLK_LOCAL_MEM_FENCE);\n"
    1854             : "    if(nTempDays != 0){\n"
    1855             : "        for (*rMonth = 1; (int)nTempDays > DaysInMonth( *rMonth, *rYear );"
    1856             : " *rMonth += 1)\n"
    1857             : "        {\n"
    1858             : "            nTempDays -= DaysInMonth( *rMonth, *rYear ); \n"
    1859             : "        }\n"
    1860             : "        *rDay = (int)nTempDays;\n"
    1861             : "    }\n"
    1862             : "}\n";
    1863             : 
    1864           0 : std::string GetYearDiff_newDecl=
    1865             : "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
    1866             : "int nMode);\n";
    1867             : 
    1868           0 : std::string GetYearDiff_new=
    1869             : "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate,"
    1870             : "int nMode )\n"
    1871             : "{\n"
    1872             : "    int   nDays1stYear;\n"
    1873             : "    int   nTotalDays = GetDiffDate_new( nNullDate, nStartDate, nEndDate,"
    1874             : "nMode, &"
    1875             : "nDays1stYear );\n"
    1876             : "    return (double)(nTotalDays)* pow((double)nDays1stYear,-1);\n"
    1877             : "}\n";
    1878             : 
    1879           0 : std::string GetDiffDate_newDecl=
    1880             : "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
    1881             : "    int* pOptDaysIn1stYear );\n";
    1882             : 
    1883           0 : std::string GetDiffDate_new=
    1884             : "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode,"
    1885             : "    int* pOptDaysIn1stYear )\n"
    1886             : "{\n"
    1887             : "    bool    bNeg = nStartDate > nEndDate;\n"
    1888             : "    if( bNeg )\n"
    1889             : "    {\n"
    1890             : "        int   n = nEndDate;\n"
    1891             : "        nEndDate = nStartDate;\n"
    1892             : "        nStartDate = n;\n"
    1893             : "    }\n"
    1894             : "    int       nRet;\n"
    1895             : "    switch( nMode )\n"
    1896             : "    {\n"
    1897             : "    case 0:   \n"
    1898             : "    case 4:   \n"
    1899             : "        {\n"
    1900             : "        int      nD1, nM1, nY1, nD2, nM2, nY2;\n"
    1901             : "        nStartDate += nNullDate;\n"
    1902             : "        nEndDate += nNullDate;\n"
    1903             : "        DaysToDate_new( nStartDate, &nD1, &nM1, &nY1 );\n"
    1904             : "        DaysToDate_new( nEndDate, &nD2, &nM2, &nY2 );\n"
    1905             : "        bool        bLeap = IsLeapYear( nY1 );\n"
    1906             : "        int       nDays, nMonths;\n"
    1907             : "        nMonths = nM2 - nM1;\n"
    1908             : "        nDays = nD2 - nD1;\n"
    1909             : "        nMonths += ( nY2 - nY1 ) * 12;\n"
    1910             : "        nRet = nMonths * 30 + nDays;\n"
    1911             : "        if( nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2 )\n"
    1912             : "            nRet -= bLeap? 1 : 2;\n"
    1913             : "        if( pOptDaysIn1stYear )\n"
    1914             : "            *pOptDaysIn1stYear = 360;\n"
    1915             : "        }\n"
    1916             : "        break;\n"
    1917             : "    case 1:    \n"
    1918             : "        if( pOptDaysIn1stYear )\n"
    1919             : "        {\n"
    1920             : "            int      nD, nM, nY;\n"
    1921             : "            DaysToDate_new( nStartDate + nNullDate, &nD, &nM, &nY );\n"
    1922             : "            *pOptDaysIn1stYear = IsLeapYear( nY )? 366 : 365;\n"
    1923             : "        }\n"
    1924             : "        nRet = nEndDate - nStartDate;\n"
    1925             : "        break;\n"
    1926             : "    case 2:      \n"
    1927             : "        nRet = nEndDate - nStartDate;\n"
    1928             : "        if( pOptDaysIn1stYear )\n"
    1929             : "            *pOptDaysIn1stYear = 360;\n"
    1930             : "        break;\n"
    1931             : "    case 3:        \n"
    1932             : "        nRet = nEndDate - nStartDate;\n"
    1933             : "        if( pOptDaysIn1stYear )\n"
    1934             : "            *pOptDaysIn1stYear = 365;\n"
    1935             : "        break;\n"
    1936             : "    }\n"
    1937             : "    return bNeg? -nRet : nRet;\n"
    1938             : "}\n";
    1939             : 
    1940             : #endif
    1941             : 
    1942             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10