Commit a9807ec1 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Fix a few type errors.

2000-08-30  Morten Welinder  <terra@diku.dk>

	* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.

	* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
 	of the guess.  Work much harder at getting an answer.

	* src/goal-seek.c (goal_seek_point): New function.
parent eef31ac7
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
......@@ -46,6 +46,7 @@ Morten:
* Fixed many bogusities in xbase plugin.
* Cleanup limits in numtheory. Added BITXOR.
* Fixed RATE, SLD, and SYD.
* Improved RATE's root searching.
Pablo De Napoli:
* New NT_MU function in numtheory.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
2000-08-30 Morten Welinder <terra@diku.dk>
* src/print-cell.c (print_show_iso8859_1): Fix a few type errors.
* src/functions/fn-financial.c (gnumeric_rate): Respect the sign
of the guess. Work much harder at getting an answer.
* src/goal-seek.c (goal_seek_point): New function.
2000-08-29 Jody Goldberg <jgoldberg@home.com>
* src/Makefile.am : Fix file names.
......
......@@ -9,6 +9,7 @@
*/
#include <config.h>
#include <math.h>
#include <limits.h>
#include "gnumeric.h"
#include "parse-util.h"
#include "cell.h"
......@@ -1549,12 +1550,11 @@ typedef struct {
static GoalSeekStatus
gnumeric_rate_f (float_t rate, float_t *y, void *user_data)
{
if (rate > -1.0) {
if (rate > -1.0 && rate != 0) {
gnumeric_rate_t *data = user_data;
*y = data->pv * calculate_pvif (rate, data->nper) +
data->pmt * (1 + rate * data->type) *
calculate_fvifa (rate, data->nper) +
data->pmt * (1 + rate * data->type) * calculate_fvifa (rate, data->nper) +
data->fv;
return GOAL_SEEK_OK;
} else
......@@ -1620,8 +1620,34 @@ gnumeric_rate (FunctionEvalInfo *ei, Value **argv)
printf ("Guess = %.15g\n", rate0);
#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;
}
/* Newton search from guess. */
status = goal_seek_newton (&gnumeric_rate_f, &gnumeric_rate_df,
&data, &udata, rate0);
if (status != GOAL_SEEK_OK) {
int factor;
/* Lay a net of test points around the guess. */
for (factor = 2; factor < 100; factor *= 2) {
goal_seek_point (&gnumeric_rate_f, &data, &udata, rate0 * factor);
goal_seek_point (&gnumeric_rate_f, &data, &udata, rate0 / factor);
}
/* Pray we got both sides of the root. */
status = goal_seek_bisection (&gnumeric_rate_f, &data, &udata);
}
if (status == GOAL_SEEK_OK) {
#if 0
printf ("Root = %.15g\n\n", data.root);
......
......@@ -9,6 +9,7 @@
*/
#include <config.h>
#include <math.h>
#include <limits.h>
#include "gnumeric.h"
#include "parse-util.h"
#include "cell.h"
......@@ -1549,12 +1550,11 @@ typedef struct {
static GoalSeekStatus
gnumeric_rate_f (float_t rate, float_t *y, void *user_data)
{
if (rate > -1.0) {
if (rate > -1.0 && rate != 0) {
gnumeric_rate_t *data = user_data;
*y = data->pv * calculate_pvif (rate, data->nper) +
data->pmt * (1 + rate * data->type) *
calculate_fvifa (rate, data->nper) +
data->pmt * (1 + rate * data->type) * calculate_fvifa (rate, data->nper) +
data->fv;
return GOAL_SEEK_OK;
} else
......@@ -1620,8 +1620,34 @@ gnumeric_rate (FunctionEvalInfo *ei, Value **argv)
printf ("Guess = %.15g\n", rate0);
#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;
}
/* Newton search from guess. */
status = goal_seek_newton (&gnumeric_rate_f, &gnumeric_rate_df,
&data, &udata, rate0);
if (status != GOAL_SEEK_OK) {
int factor;
/* Lay a net of test points around the guess. */
for (factor = 2; factor < 100; factor *= 2) {
goal_seek_point (&gnumeric_rate_f, &data, &udata, rate0 * factor);
goal_seek_point (&gnumeric_rate_f, &data, &udata, rate0 / factor);
}
/* Pray we got both sides of the root. */
status = goal_seek_bisection (&gnumeric_rate_f, &data, &udata);
}
if (status == GOAL_SEEK_OK) {
#if 0
printf ("Root = %.15g\n\n", data.root);
......
......@@ -111,6 +111,31 @@ goal_seek_initialise (GoalSeekData *data)
data->precision = 1e-10;
}
/*
* Seek a goal using a single point.
*/
GoalSeekStatus
goal_seek_point (GoalSeekFunction f, GoalSeekData *data,
void *user_data, float_t x0)
{
GoalSeekStatus status;
float_t y0;
if (x0 < data->xmin || x0 > data->xmax)
return GOAL_SEEK_ERROR;
status = f (x0, &y0, user_data);
if (status != GOAL_SEEK_OK)
return status;
if (update_data (x0, y0, data))
return GOAL_SEEK_OK;
return GOAL_SEEK_ERROR;
}
/*
* Seek a goal (root) using Newton's iterative method.
*
......
......@@ -26,6 +26,11 @@ typedef GoalSeekStatus (*GoalSeekFunction) (float_t x, float_t *y, void *user_da
void goal_seek_initialise (GoalSeekData *data);
GoalSeekStatus goal_seek_point (GoalSeekFunction f,
GoalSeekData *data,
void *user_data,
float_t x0);
GoalSeekStatus goal_seek_newton (GoalSeekFunction f,
GoalSeekFunction df,
GoalSeekData *data,
......
......@@ -52,12 +52,12 @@ print_hline (GnomePrintContext *context,
int
print_show_iso8859_1 (GnomePrintContext *pc, char const *text)
{
guint32 u4text[128];
guint32 u4text[128], *u4p;
guint32 *dynp = NULL;
size_t len;
int ret;
char const *p;
char *u4p, *outp;
char *outp;
g_return_val_if_fail (pc && text, -1);
......
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