Commit 4a6dcac2 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Prefer absolute lowest y-value in cases where we have only one side of

2001-06-22  Morten Welinder  <terra@diku.dk>

	* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
 	cases where we have only one side of zero.

2001-06-22  Morten Welinder  <terra@diku.dk>

	* fn-financial.c (gnumeric_rate, gnumeric_irr): No longer respect
 	sign of guess.  It's a nice idea, but breaks tests.


(White-space samba in plugins/excel/ms-excel-read.c)
parent 95cb53c4
2001-06-22 Morten Welinder <terra@diku.dk>
* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
cases where we have only one side of zero.
2001-06-21 Morten Welinder <terra@diku.dk>
* src/summary.c: #include <string.h> for strlen.
......
......@@ -34,6 +34,8 @@ Morten:
* Applied some much-needed TLC to fn-financial.c and fn-eng.c.
* Speed-up Gnumeric function calls.
* Killed a zillion problems pointed out by gcc 3.0 warnings.
* Improve goal seeking slightly.
* Fix RATE and IRR.
Zbigniew:
* More work on plugin system.
......
2001-06-22 Morten Welinder <terra@diku.dk>
* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
cases where we have only one side of zero.
2001-06-21 Morten Welinder <terra@diku.dk>
* src/summary.c: #include <string.h> for strlen.
......
2001-06-22 Morten Welinder <terra@diku.dk>
* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
cases where we have only one side of zero.
2001-06-21 Morten Welinder <terra@diku.dk>
* src/summary.c: #include <string.h> for strlen.
......
2001-06-22 Morten Welinder <terra@diku.dk>
* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
cases where we have only one side of zero.
2001-06-21 Morten Welinder <terra@diku.dk>
* src/summary.c: #include <string.h> for strlen.
......
2001-06-22 Morten Welinder <terra@diku.dk>
* src/goal-seek.c (update_data): Prefer absolute lowest y-value in
cases where we have only one side of zero.
2001-06-21 Morten Welinder <terra@diku.dk>
* src/summary.c: #include <string.h> for strlen.
......
This diff is collapsed.
......@@ -1603,16 +1603,10 @@ gnumeric_rate (FunctionEvalInfo *ei, Value **argv)
#endif
goal_seek_initialise (&data);
/* Respect the sign of the guess. */
if (rate0 >= 0) {
data.xmin = 0;
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
} else {
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
data.xmax = 0;
}
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
/* Newton search from guess. */
status = goal_seek_newton (&gnumeric_rate_f, &gnumeric_rate_df,
......@@ -1735,16 +1729,10 @@ gnumeric_irr (FunctionEvalInfo *ei, Value **argv)
goal_seek_initialise (&data);
/* Respect the sign of the guess. */
if (rate0 >= 0) {
data.xmin = 0;
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / (p.n + 1)) - 1);
} else {
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / (p.n + 1)) + 1);
data.xmax = 0;
}
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / p.n) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / p.n) - 1);
status = goal_seek_newton (&irr_npv, &irr_npv_df, &data, &p, rate0);
if (status != GOAL_SEEK_OK) {
......
2001-06-22 Morten Welinder <terra@diku.dk>
* fn-financial.c (gnumeric_rate, gnumeric_irr): No longer respect
sign of guess. It's a nice idea, but breaks tests.
2001-06-21 Morten Welinder <terra@diku.dk>
* fn-stat.c: #include <string.h> for memset.
......
......@@ -1603,16 +1603,10 @@ gnumeric_rate (FunctionEvalInfo *ei, Value **argv)
#endif
goal_seek_initialise (&data);
/* Respect the sign of the guess. */
if (rate0 >= 0) {
data.xmin = 0;
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
} else {
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
data.xmax = 0;
}
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
/* Newton search from guess. */
status = goal_seek_newton (&gnumeric_rate_f, &gnumeric_rate_df,
......@@ -1735,16 +1729,10 @@ gnumeric_irr (FunctionEvalInfo *ei, Value **argv)
goal_seek_initialise (&data);
/* Respect the sign of the guess. */
if (rate0 >= 0) {
data.xmin = 0;
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / (p.n + 1)) - 1);
} else {
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / (p.n + 1)) + 1);
data.xmax = 0;
}
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / p.n) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / p.n) - 1);
status = goal_seek_newton (&irr_npv, &irr_npv_df, &data, &p, rate0);
if (status != GOAL_SEEK_OK) {
......
......@@ -34,8 +34,17 @@ update_data (gnum_float x, gnum_float y, GoalSeekData *data)
{
if (y > 0) {
if (data->havexpos) {
if (data->havexneg &&
fabs (x - data->xneg) < fabs (data->xpos - data->xneg)) {
if (data->havexneg) {
/*
* When we have pos and neg, prefer the new point only
* if it makes the pos-neg x-internal smaller.
*/
if (fabs (x - data->xneg) < fabs (data->xpos - data->xneg)) {
data->xpos = x;
data->ypos = y;
}
} else if (y < data->ypos) {
/* We have pos only and our neg y is closer to zero. */
data->xpos = x;
data->ypos = y;
}
......@@ -47,11 +56,21 @@ update_data (gnum_float x, gnum_float y, GoalSeekData *data)
return FALSE;
} else if (y < 0) {
if (data->havexneg) {
if (data->havexpos &&
fabs (x - data->xpos) < fabs (data->xpos - data->xneg)) {
if (data->havexpos) {
/*
* When we have pos and neg, prefer the new point only
* if it makes the pos-neg x-internal smaller.
*/
if (fabs (x - data->xpos) < fabs (data->xpos - data->xneg)) {
data->xneg = x;
data->yneg = y;
}
} else if (-y < -data->yneg) {
/* We have neg only and our neg y is closer to zero. */
data->xneg = x;
data->yneg = y;
}
} else {
data->xneg = x;
data->yneg = y;
......
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