Commit 8213cf77 authored by Andreas J. Guelzow's avatar Andreas J. Guelzow Committed by Andreas J. Guelzow

Change parameters in calls to coupdaysnc, coupdaybs and coupdays.

2002-01-15  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* fn-financial.c : Change parameters in calls to coupdaysnc,
	coupdaybs and coupdays.
	(func_coup_cd) : extract common code from
	  gnumeric_coupncd and gnumeric_couppcd (proposed by Neil Booth)
	(gnumeric_coupncd) : change into wrapper for func_coup_cd
	(gnumeric_couppcd) : change into wrapper for func_coup_cd

2002-01-15  Andreas J. Guelzow <aguelzow@taliesin.ca>

	* src/datetime.c (coup_cd_xl) : new function (XL compatible
	  implementation of coup_cd.
	(coupdays) : add xl boolean parameter, call coup_cd or coup_cd_xl
	  depending on xl.
	(coupdaybs) : ditto
	(coupdaysnc) : ditto
	* src/datetime.h (coupdays) : add xl boolean parameter
	(coupdaybs) : ditto
	(coupdaysnc) : ditto
parent 83bedf04
2002-01-15 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/datetime.c (coup_cd_xl) : new function (XL compatible
implementation of coup_cd.
(coupdays) : add xl boolean parameter, call coup_cd or coup_cd_xl
depending on xl.
(coupdaybs) : ditto
(coupdaysnc) : ditto
* src/datetime.h (coupdays) : add xl boolean parameter
(coupdaybs) : ditto
(coupdaysnc) : ditto
2002-01-15 Jody Goldberg <jody@gnome.org>
* src/xml-io.c (xml_read_cell) : be more robust when faced
......
2002-01-15 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/datetime.c (coup_cd_xl) : new function (XL compatible
implementation of coup_cd.
(coupdays) : add xl boolean parameter, call coup_cd or coup_cd_xl
depending on xl.
(coupdaybs) : ditto
(coupdaysnc) : ditto
* src/datetime.h (coupdays) : add xl boolean parameter
(coupdaybs) : ditto
(coupdaysnc) : ditto
2002-01-15 Jody Goldberg <jody@gnome.org>
* src/xml-io.c (xml_read_cell) : be more robust when faced
......
2002-01-15 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/datetime.c (coup_cd_xl) : new function (XL compatible
implementation of coup_cd.
(coupdays) : add xl boolean parameter, call coup_cd or coup_cd_xl
depending on xl.
(coupdaybs) : ditto
(coupdaysnc) : ditto
* src/datetime.h (coupdays) : add xl boolean parameter
(coupdaybs) : ditto
(coupdaysnc) : ditto
2002-01-15 Jody Goldberg <jody@gnome.org>
* src/xml-io.c (xml_read_cell) : be more robust when faced
......
2002-01-15 Andreas J. Guelzow <aguelzow@taliesin.ca>
* src/datetime.c (coup_cd_xl) : new function (XL compatible
implementation of coup_cd.
(coupdays) : add xl boolean parameter, call coup_cd or coup_cd_xl
depending on xl.
(coupdaybs) : ditto
(coupdaysnc) : ditto
* src/datetime.h (coupdays) : add xl boolean parameter
(coupdaybs) : ditto
(coupdaysnc) : ditto
2002-01-15 Jody Goldberg <jody@gnome.org>
* src/xml-io.c (xml_read_cell) : be more robust when faced
......
......@@ -301,6 +301,45 @@ coupnum (GDate *settlement, GDate *maturity, int freq, int basis)
- (months < -9) - (months == -9 && days <= 0);
}
static Value *
func_coup_cd (FunctionEvalInfo *ei, Value **argv, gboolean next)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, xl, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 5 || ((12/freq) * freq != 12)
|| g_date_compare (settlement, maturity) >= 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = xl ? coup_cd_xl (settlement, maturity, freq, next) :
coup_cd (settlement, maturity, freq, oem, next);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
}
/***************************************************************************
......@@ -2280,9 +2319,9 @@ gnumeric_price (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
sum = 0.0;
......@@ -2368,9 +2407,9 @@ gnumeric_yield (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
if (n <= 1.0) {
......@@ -2539,10 +2578,10 @@ gnumeric_oddfprice (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
ds = -1; /* FIXME */
df = -1; /* FIXME */
e = coupdays (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
/*
......@@ -2785,12 +2824,14 @@ gnumeric_coupdaybs (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2803,7 +2844,7 @@ gnumeric_coupdaybs (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_float (coupdaybs (settlement, maturity, freq, basis, oem));
result = value_new_float (coupdaybs (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2850,12 +2891,14 @@ gnumeric_coupdays (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2868,7 +2911,7 @@ gnumeric_coupdays (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_int (coupdays (settlement, maturity, freq, basis, oem));
result = value_new_int (coupdays (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2915,12 +2958,14 @@ gnumeric_coupdaysnc (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2933,7 +2978,7 @@ gnumeric_coupdaysnc (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_float (coupdaysnc (settlement, maturity, freq, basis, oem));
result = value_new_float (coupdaysnc (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2974,39 +3019,7 @@ static char *help_coupncd = {
static Value *
gnumeric_coupncd (FunctionEvalInfo *ei, Value **argv)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 4 || (freq != 1 && freq != 2 && freq != 4)
|| g_date_compare (settlement, maturity) > 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = coup_cd (settlement, maturity, freq, oem,TRUE);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
return func_coup_cd (ei, argv, TRUE);
}
/***************************************************************************/
......@@ -3041,39 +3054,7 @@ static char *help_couppcd = {
static Value *
gnumeric_couppcd (FunctionEvalInfo *ei, Value **argv)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 4 || (freq != 1 && freq != 2 && freq != 4)
|| g_date_compare (settlement, maturity) > 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = coup_cd (settlement, maturity, freq, oem, FALSE);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
return func_coup_cd (ei, argv, FALSE);
}
/***************************************************************************/
......
......@@ -351,6 +351,8 @@ adjust_dates_basis (GDate *from, GDate *to, int basis)
return;
}
/* ------------------------------------------------------------------------- */
/*
* days_between_dep_basis
*
......@@ -419,6 +421,7 @@ days_between_dep_basis (GDate *from, GDate *to, int basis)
}
}
/* ------------------------------------------------------------------------- */
/*
* coup_cd
......@@ -472,6 +475,54 @@ coup_cd (GDate *settlement, GDate *maturity, int freq, gboolean oem, gboolean ne
return result;
}
/* ------------------------------------------------------------------------- */
/*
* coup_cd_xl
*
* @settlement: GDate *
* @maturity : GDate * must follow settlement strictly
* @freq : int divides 12 evenly
* @oem : gboolean whether to do special end of month
* handling
* @next : gboolean whether next or previous date
*
* returns : GDate * date as returned by XL
*
* this function does not depend on the basis of counting!
*/
GDate *
coup_cd_xl (GDate *settlement, GDate *maturity, int freq, gboolean next)
{
GDate *result;
GDate coupon;
gboolean is_oem_special;
int months = 12 / freq;
is_oem_special = g_date_is_last_of_month (maturity);
result = g_date_new();
g_date_clear (&coupon, 1);
g_date_set_julian (&coupon, g_date_julian (maturity));
do {
g_date_set_julian (result, g_date_julian (&coupon));
g_date_subtract_months (&coupon, months);
if (is_oem_special)
while (!g_date_is_last_of_month (&coupon))
g_date_add_days (&coupon, 1);
} while (g_date_compare (settlement, &coupon) < 0 );
if (!next) {
g_date_set_julian (result, g_date_julian (&coupon));
}
return result;
}
/* ------------------------------------------------------------------------- */
/*
......@@ -479,7 +530,8 @@ coup_cd (GDate *settlement, GDate *maturity, int freq, gboolean oem, gboolean ne
* Currently, returns negative numbers if the branch is not implemented.
*/
int
coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl)
{
GDate *prev;
GDate *next;
......@@ -496,8 +548,10 @@ coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
/* Now we need to look at the real coupon dates */
prev = coup_cd (settlement, maturity, freq, oem, FALSE);
next = coup_cd (settlement, maturity, freq, oem, TRUE);
prev = xl ? coup_cd_xl (settlement, maturity, freq, FALSE) :
coup_cd (settlement, maturity, freq, oem, FALSE);
next = xl ? coup_cd_xl (settlement, maturity, freq, TRUE) :
coup_cd (settlement, maturity, freq, oem, TRUE);
adjust_dates_basis (prev, next, basis);
days = days_between_dep_basis (prev, next, basis);
g_date_free (prev);
......@@ -505,6 +559,7 @@ coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
return days;
}
/* ------------------------------------------------------------------------- */
/*
......@@ -512,32 +567,41 @@ coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
* the settlement date.
*/
int
coupdaybs (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
coupdaybs (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl)
{
GDate *prev_coupon;
int days;
prev_coupon = coup_cd (settlement, maturity, freq, oem, FALSE);
prev_coupon = xl ? coup_cd_xl (settlement, maturity, freq, FALSE) :
coup_cd (settlement, maturity, freq, oem, FALSE);
adjust_dates_basis (settlement, prev_coupon, basis);
days = - days_between_dep_basis (settlement, prev_coupon, basis);
g_date_free (prev_coupon);
return days;
}
/* ------------------------------------------------------------------------- */
/*
* Returns the number of days from the settlement date to the next
* coupon date.
*/
int
coupdaysnc (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem)
coupdaysnc (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl)
{
GDate *next_coupon;
int days;
next_coupon = coup_cd (settlement, maturity, freq, oem, TRUE);
next_coupon = xl ? coup_cd_xl (settlement, maturity, freq, TRUE) :
coup_cd (settlement, maturity, freq, oem, TRUE);
adjust_dates_basis (settlement, next_coupon, basis);
days = days_between_dep_basis (settlement, next_coupon, basis);
g_date_free (next_coupon);
return days;
}
/* ------------------------------------------------------------------------- */
......@@ -71,12 +71,16 @@ void adjust_dates_basis (GDate *from, GDate *to, int basis);
gint32 days_between_dep_basis (GDate *from, GDate *to, int basis);
GDate * coup_cd (GDate *settlement, GDate *maturity, int freq, gboolean oem, gboolean next);
GDate * coup_cd_xl (GDate *settlement, GDate *maturity, int freq, gboolean next);
int coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem);
int coupdays (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl);
int coupdaybs (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem);
int coupdaybs (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl);
int coupdaysnc (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem);
int coupdaysnc (GDate *settlement, GDate *maturity, int freq, int basis, gboolean oem,
gboolean xl);
#endif
2002-01-15 Andreas J. Guelzow <aguelzow@taliesin.ca>
* fn-financial.c : Change parameters in calls to coupdaysnc,
coupdaybs and coupdays.
(func_coup_cd) : extract common code from
gnumeric_coupncd and gnumeric_couppcd (proposed by Neil Booth)
(gnumeric_coupncd) : change into wrapper for func_coup_cd
(gnumeric_couppcd) : change into wrapper for func_coup_cd
2002-01-14 Andreas J. Guelzow <aguelzow@taliesin.ca>
* fn-financial.c (coupdays) : rewrite and move to datetime.c
......
......@@ -301,6 +301,45 @@ coupnum (GDate *settlement, GDate *maturity, int freq, int basis)
- (months < -9) - (months == -9 && days <= 0);
}
static Value *
func_coup_cd (FunctionEvalInfo *ei, Value **argv, gboolean next)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, xl, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 5 || ((12/freq) * freq != 12)
|| g_date_compare (settlement, maturity) >= 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = xl ? coup_cd_xl (settlement, maturity, freq, next) :
coup_cd (settlement, maturity, freq, oem, next);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
}
/***************************************************************************
......@@ -2280,9 +2319,9 @@ gnumeric_price (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
sum = 0.0;
......@@ -2368,9 +2407,9 @@ gnumeric_yield (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
d = coupdaysnc (settlement, maturity, freq, basis, TRUE, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
if (n <= 1.0) {
......@@ -2539,10 +2578,10 @@ gnumeric_oddfprice (FunctionEvalInfo *ei, Value **argv)
goto out;
}
a = coupdaybs (settlement, maturity, freq, basis, TRUE);
a = coupdaybs (settlement, maturity, freq, basis, TRUE, TRUE);
ds = -1; /* FIXME */
df = -1; /* FIXME */
e = coupdays (settlement, maturity, freq, basis, TRUE);
e = coupdays (settlement, maturity, freq, basis, TRUE, TRUE);
n = coupnum (settlement, maturity, freq, basis);
/*
......@@ -2785,12 +2824,14 @@ gnumeric_coupdaybs (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2803,7 +2844,7 @@ gnumeric_coupdaybs (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_float (coupdaybs (settlement, maturity, freq, basis, oem));
result = value_new_float (coupdaybs (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2850,12 +2891,14 @@ gnumeric_coupdays (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2868,7 +2911,7 @@ gnumeric_coupdays (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_int (coupdays (settlement, maturity, freq, basis, oem));
result = value_new_int (coupdays (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2915,12 +2958,14 @@ gnumeric_coupdaysnc (FunctionEvalInfo *ei, Value **argv)
int freq, basis;
Value *result;
gboolean oem, err = FALSE;
gboolean xl;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : 0;
xl = argv[4] ? FALSE : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2933,7 +2978,7 @@ gnumeric_coupdaysnc (FunctionEvalInfo *ei, Value **argv)
goto out;
}
result = value_new_float (coupdaysnc (settlement, maturity, freq, basis, oem));
result = value_new_float (coupdaysnc (settlement, maturity, freq, basis, oem, xl));
out:
g_date_free (settlement);
......@@ -2974,39 +3019,7 @@ static char *help_coupncd = {
static Value *
gnumeric_coupncd (FunctionEvalInfo *ei, Value **argv)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 4 || (freq != 1 && freq != 2 && freq != 4)
|| g_date_compare (settlement, maturity) > 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = coup_cd (settlement, maturity, freq, oem,TRUE);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
return func_coup_cd (ei, argv, TRUE);
}
/***************************************************************************/
......@@ -3041,39 +3054,7 @@ static char *help_couppcd = {
static Value *
gnumeric_couppcd (FunctionEvalInfo *ei, Value **argv)
{
GDate *settlement;
GDate *maturity;
GDate *date;
int freq, basis;
gboolean oem, err = FALSE;
Value *result;
settlement = datetime_value_to_g (argv[0]);
maturity = datetime_value_to_g (argv[1]);
freq = value_get_as_int (argv[2]);
basis = argv[3] ? value_get_as_int (argv[3]) : 0;
oem = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
if (!maturity || !settlement || err) {
result = value_new_error (ei->pos, gnumeric_err_VALUE);
goto out;
}
if (basis < 0 || basis > 4 || (freq != 1 && freq != 2 && freq != 4)
|| g_date_compare (settlement, maturity) > 0) {
result = value_new_error (ei->pos, gnumeric_err_NUM);
goto out;
}
date = coup_cd (settlement, maturity, freq, oem, FALSE);
result = value_new_int (datetime_g_to_serial (date));
g_date_free (date);
out:
g_date_free (settlement);
g_date_free (maturity);
return result;
return func_coup_cd (ei, argv, FALSE);
}
/***************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment