Commit 653bc803 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Constify.

2002-02-21  Morten Welinder  <terra@diku.dk>

	* src/workbook-control-gui.c (wbcg_validation_msg): Constify.

	* src/cell.c (cell_is_zero): Use gnum_float.

	* src/regression.c (LUPDecomp): Use gnumabs.
	* src/solver-lp.c (solver_answer_report): Ditto.
	* src/value.c (value_diff): Ditto.
	* src/goal-seek.c: Ditto.
	* src/rangefunc.c (range_avedev): Ditto.

	* src/validation.c (validation_eval): Use gnum_float, modfgnum,
	and gnumabs.

	* src/numbers.h (GNUM_MANT_DIG, GNUM_MAX_EXP, gnumabs): New stuff.
parent b87566ff
2002-02-21 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (wbcg_validation_msg): Constify.
* src/cell.c (cell_is_zero): Use gnum_float.
* src/regression.c (LUPDecomp): Use gnumabs.
* src/solver-lp.c (solver_answer_report): Ditto.
* src/value.c (value_diff): Ditto.
* src/goal-seek.c: Ditto.
* src/rangefunc.c (range_avedev): Ditto.
* src/validation.c (validation_eval): Use gnum_float, modfgnum,
and gnumabs.
* src/numbers.h (GNUM_MANT_DIG, GNUM_MAX_EXP, gnumabs): New stuff.
2002-02-21 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (callback): Fix formats.
......
2002-02-21 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (wbcg_validation_msg): Constify.
* src/cell.c (cell_is_zero): Use gnum_float.
* src/regression.c (LUPDecomp): Use gnumabs.
* src/solver-lp.c (solver_answer_report): Ditto.
* src/value.c (value_diff): Ditto.
* src/goal-seek.c: Ditto.
* src/rangefunc.c (range_avedev): Ditto.
* src/validation.c (validation_eval): Use gnum_float, modfgnum,
and gnumabs.
* src/numbers.h (GNUM_MANT_DIG, GNUM_MAX_EXP, gnumabs): New stuff.
2002-02-21 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (callback): Fix formats.
......
2002-02-21 Morten Welinder <terra@diku.dk>
* src/workbook-control-gui.c (wbcg_validation_msg): Constify.
* src/cell.c (cell_is_zero): Use gnum_float.
* src/regression.c (LUPDecomp): Use gnumabs.
* src/solver-lp.c (solver_answer_report): Ditto.
* src/value.c (value_diff): Ditto.
* src/goal-seek.c: Ditto.
* src/rangefunc.c (range_avedev): Ditto.
* src/validation.c (validation_eval): Use gnum_float, modfgnum,
and gnumabs.
* src/numbers.h (GNUM_MANT_DIG, GNUM_MAX_EXP, gnumabs): New stuff.
2002-02-21 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (callback): Fix formats.
......
......@@ -46,7 +46,7 @@ AC_PATH_PROG(GDK_PIXBUF_CSOURCE, gdk-pixbuf-csource)
GNOME_COMPILE_WARNINGS
set_mode_warnings=yes
if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
for option in -Wsign-promo -Wsign-compare -Wpointer-arith -Wnested-externs -Wchar-subscripts -Wwrite-strings -Wformat; do
for option in -Wsign-promo -Wsign-compare -Wpointer-arith -Wnested-externs -Wchar-subscripts -Wwrite-strings; do
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $option"
AC_MSG_CHECKING([whether gcc understands $option])
......@@ -72,7 +72,7 @@ AC_ARG_WITH(long_double,
if test "$ac_cv_c_long_double" != "yes"; then
AC_MSG_ERROR([Long double type is not available.])
fi
AC_CHECK_FUNCS(strtold modfl string_to_decimal decimal_to_quadruple)
AC_CHECK_FUNCS(strtold modfl fabsl string_to_decimal decimal_to_quadruple)
AC_CHECK_HEADERS(floatingpoint.h)
if test "$ac_cv_func_strtold" = "yes"; then
......@@ -84,9 +84,11 @@ AC_ARG_WITH(long_double,
else
AC_MSG_WARN([You lack the strtold function -- precision will be impaired])
fi
if test "$ac_cv_func_modfl" != "yes"; then
AC_MSG_WARN([You lack the modfl function -- precision will be impaired])
fi
float_msg="long double (EXPERIMENTAL)"
AC_MSG_WARN([Long double support is experimental -- expect problems])
AC_DEFINE(WITH_LONG_DOUBLE)
......@@ -573,6 +575,7 @@ Configuration:
Source code location: ${srcdir}
Compiler: ${CC}
Compiler flags: ${CFLAGS}
Floating point type: ${float_msg}
MS Excel Support: ${excel_msg}
......
......@@ -114,7 +114,7 @@ gnumeric_unix2date (FunctionEvalInfo *ei, Value **argv)
time_t utime = (time_t)futime;
/* Check for overflow. */
if (fabs (futime - utime) >= 1.0)
if (gnumabs (futime - utime) >= 1.0)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (datetime_timet_to_serial_raw (utime) +
......@@ -146,7 +146,7 @@ gnumeric_date2unix (FunctionEvalInfo *ei, Value **argv)
time_t utime = datetime_serial_to_timet (serial);
/* Check for overflow. */
if (fabs (fserial - serial) >= 1.0 || utime == (time_t)-1)
if (gnumabs (fserial - serial) >= 1.0 || utime == (time_t)-1)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (utime + DAY_SECONDS * (fserial - serial));
......
......@@ -243,7 +243,7 @@ static const char *help_abs = {
static Value *
gnumeric_abs (FunctionEvalInfo *ei, Value **args)
{
return value_new_float (fabs (value_get_as_float (args [0])));
return value_new_float (gnumabs (value_get_as_float (args [0])));
}
/***************************************************************************/
......
......@@ -3463,9 +3463,9 @@ gnumeric_ttest (FunctionEvalInfo *ei, Value *argv[])
}
if (tails == 1)
p = 1.0 - pt (fabs (x), dof);
p = 1.0 - pt (gnumabs (x), dof);
else
p = (1.0 - pt (fabs (x), dof)) * 2;
p = (1.0 - pt (gnumabs (x), dof)) * 2;
return value_new_float (p);
}
......
......@@ -593,7 +593,7 @@ cell_is_zero (Cell const *cell)
case VALUE_INTEGER : return v->v_int.val == 0;
case VALUE_FLOAT :
{
double const res = v->v_float.val;
gnum_float res = v->v_float.val;
return (-1e-10 < res && res < 1e-10);
}
......
......@@ -651,7 +651,7 @@ render_number (GString *result,
format_info_t const *info)
{
char thousands_sep = format_get_thousand ();
char num_buf[(DBL_MANT_DIG + DBL_MAX_EXP) * 2 + 1];
char num_buf[(GNUM_MANT_DIG + GNUM_MAX_EXP) * 2 + 1];
gchar *num = num_buf + sizeof (num_buf) - 1;
gnum_float frac_part, int_part;
int group, zero_count, digit_count = 0;
......
2002-02-21 Morten Welinder <terra@diku.dk>
* fn-math.c (gnumeric_abs): Use gnumabs.
* fn-stat.c (gnumeric_ttest): Ditto.
* fn-date.c (gnumeric_date2unix, gnumeric_unix2date): Ditto.
2002-02-20 Jody Goldberg <jody@gnome.org>
* fn-lookup.c (HLOOKUP,VLOOKUP) : offer an 'as_index' flag.
......
......@@ -114,7 +114,7 @@ gnumeric_unix2date (FunctionEvalInfo *ei, Value **argv)
time_t utime = (time_t)futime;
/* Check for overflow. */
if (fabs (futime - utime) >= 1.0)
if (gnumabs (futime - utime) >= 1.0)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (datetime_timet_to_serial_raw (utime) +
......@@ -146,7 +146,7 @@ gnumeric_date2unix (FunctionEvalInfo *ei, Value **argv)
time_t utime = datetime_serial_to_timet (serial);
/* Check for overflow. */
if (fabs (fserial - serial) >= 1.0 || utime == (time_t)-1)
if (gnumabs (fserial - serial) >= 1.0 || utime == (time_t)-1)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (utime + DAY_SECONDS * (fserial - serial));
......
......@@ -243,7 +243,7 @@ static const char *help_abs = {
static Value *
gnumeric_abs (FunctionEvalInfo *ei, Value **args)
{
return value_new_float (fabs (value_get_as_float (args [0])));
return value_new_float (gnumabs (value_get_as_float (args [0])));
}
/***************************************************************************/
......
......@@ -3463,9 +3463,9 @@ gnumeric_ttest (FunctionEvalInfo *ei, Value *argv[])
}
if (tails == 1)
p = 1.0 - pt (fabs (x), dof);
p = 1.0 - pt (gnumabs (x), dof);
else
p = (1.0 - pt (fabs (x), dof)) * 2;
p = (1.0 - pt (gnumabs (x), dof)) * 2;
return value_new_float (p);
}
......
......@@ -12,6 +12,7 @@
#endif
#include <gnumeric-config.h>
#include "numbers.h"
#include "gnumeric.h"
#include "goal-seek.h"
......@@ -34,7 +35,7 @@ update_data (gnum_float x, gnum_float y, GoalSeekData *data)
* 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)) {
if (gnumabs (x - data->xneg) < gnumabs (data->xpos - data->xneg)) {
data->xpos = x;
data->ypos = y;
}
......@@ -56,7 +57,7 @@ update_data (gnum_float x, gnum_float y, GoalSeekData *data)
* 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)) {
if (gnumabs (x - data->xpos) < gnumabs (data->xpos - data->xneg)) {
data->xneg = x;
data->yneg = y;
}
......@@ -197,7 +198,7 @@ goal_seek_newton (GoalSeekFunction f, GoalSeekFunction df,
gnum_float xstep;
if (data->havexneg && data->havexpos)
xstep = fabs (data->xpos - data->xneg) / 1e6;
xstep = gnumabs (data->xpos - data->xneg) / 1e6;
else
xstep = (data->xmax - data->xmin) / 1e6;
......@@ -220,7 +221,7 @@ goal_seek_newton (GoalSeekFunction f, GoalSeekFunction df,
return GOAL_SEEK_OK;
}
stepsize = fabs (x1 - x0) / (fabs (x0) + fabs (x1));
stepsize = gnumabs (x1 - x0) / (gnumabs (x0) + gnumabs (x1));
#ifdef DEBUG_GOAL_SEEK
printf (" df0 = %.20" GNUM_FORMAT_g "\n", df0);
......@@ -268,8 +269,8 @@ goal_seek_bisection (GoalSeekFunction f, GoalSeekData *data, void *user_data)
if (!data->havexpos || !data->havexneg)
return GOAL_SEEK_ERROR;
stepsize = fabs (data->xpos - data->xneg)
/ (fabs (data->xpos) + fabs (data->xneg));
stepsize = gnumabs (data->xpos - data->xneg)
/ (gnumabs (data->xpos) + gnumabs (data->xneg));
/* log_2 (10) = 3.3219 < 4. */
for (iterations = 0; iterations < 100 + GNUM_DIG * 4; iterations++) {
......@@ -341,7 +342,7 @@ goal_seek_bisection (GoalSeekFunction f, GoalSeekData *data, void *user_data)
continue;
}
xstep = fabs (data->xpos - data->xneg) / 1e6;
xstep = gnumabs (data->xpos - data->xneg) / 1e6;
status = fake_df (f, x0, &df0, xstep, data, user_data);
if (status != GOAL_SEEK_OK)
continue;
......@@ -385,8 +386,8 @@ goal_seek_bisection (GoalSeekFunction f, GoalSeekData *data, void *user_data)
return GOAL_SEEK_OK;
}
stepsize = fabs (data->xpos - data->xneg)
/ (fabs (data->xpos) + fabs (data->xneg));
stepsize = gnumabs (data->xpos - data->xneg)
/ (gnumabs (data->xpos) + gnumabs (data->xneg));
#ifdef DEBUG_GOAL_SEEK
printf (" ss = %.20" GNUM_FORMAT_g "\n", stepsize);
......
......@@ -550,36 +550,53 @@ gnumeric_strescape (const char *string)
/* ------------------------------------------------------------------------- */
#ifdef NEED_FAKE_MODFL
#ifdef NEED_FAKE_MODFGNUM
gnum_float
fake_modfl (gnum_float x, gnum_float *iptr)
modfgnum (gnum_float x, gnum_float *iptr)
{
double di;
gnum_float res;
static gboolean warned = FALSE;
res = modf (x, &di);
if (!warned) {
warned = TRUE;
g_warning (_("This version of Gnumeric has been compiled with inadequate precision in modfgnum."));
}
/* Throw away the fractional part. Hope the integer part fits. */
(void)modf (x, &di);
*iptr = di;
return res;
return x - di;
}
#endif
/* ------------------------------------------------------------------------- */
#ifdef NEED_FAKE_GNUMABS
gnum_float
gnumabs (gnum_float x)
{
return (x >= 0) ? x : -x;
}
#endif
/* ------------------------------------------------------------------------- */
#if defined(WITH_LONG_DOUBLE) && !defined(HAVE_STRTOLD)
#ifdef NEED_FAKE_STRTOGNUM
gnum_float
strtognum (const char *str, char **end)
{
gnum_float res;
#if defined(HAVE_STRING_TO_DECIMAL) && defined(HAVE_DECIMAL_TO_QUADRUPLE)
gnum_float res;
decimal_record dr;
enum decimal_string_form form;
decimal_mode dm;
fp_exception_field_type excp;
char *echar;
string_to_decimal ((char **)&str, strlen (str),
0, &dr, &form, &echar);
string_to_decimal ((char **)&str, INT_MAX, 0,
&dr, &form, &echar);
if (end) *end = (char *)str;
if (form == invalid_form) {
......@@ -588,21 +605,31 @@ strtognum (const char *str, char **end)
}
dm.rd = fp_nearest;
dm.df = floating_form;
dm.ndigits = GNUM_DIG;
decimal_to_quadruple (&res, &dm, &dr, &excp);
if (excp & ((1 << fp_overflow) | (1 << fp_underflow)))
errno = ERANGE;
return res;
#else
static gboolean warned = FALSE;
if (!warned) {
warned = TRUE;
g_warning (_("This version of Gnumeric has been compiled with inadequate precision in strtognum."));
}
res = strtod (str, end);
char *myend;
gnum_float res;
int count;
if (end == 0) end = &myend;
(void) strtod (str, end);
if (str == *end)
return 0;
errno = 0;
count = sscanf (str, "%Lf", &res);
if (count == 1)
return res;
/* Now what? */
*end = (char *)str;
errno = ERANGE;
return 0.0;
#endif
return res;
}
#endif
/* ------------------------------------------------------------------------- */
......@@ -83,11 +83,15 @@ void gnumeric_set_le_double (void *p, double d);
char * gnumeric_strescape (const char *string);
#ifdef NEED_FAKE_MODFL
#ifdef NEED_FAKE_MODFGNUM
gnum_float fake_modfl (gnum_float x, gnum_float *iptr);
#endif
#if defined(WITH_LONG_DOUBLE) && !defined(HAVE_STRTOLD)
#ifdef NEED_FAKE_GNUMABS
gnum_float gnumabs (gnum_float x);
#endif
#ifdef NEED_FAKE_STRTOGNUM
gnum_float strtognum (const char *str, char **end);
#endif
......
......@@ -10,14 +10,22 @@ typedef long double gnum_float;
#ifdef HAVE_STRTOLD
#define strtognum strtold
#else
#define NEED_FAKE_STRTOGNUM
/* Defined in gutils.h */
#endif
#ifdef HAVE_MODFL
#define modfgnum modfl
#else
#define NEED_FAKE_MODFL
#define modfgnum fake_modfl
#define NEED_FAKE_MODFGNUM
/* Defined in gutils.h */
#endif
#ifdef HAVE_FABSL
#define gnumabs fabsl
#else
#define NEED_FAKE_GNUMABS
/* Defined in gutils.h */
#endif
#define GNUM_FORMAT_e "Le"
......@@ -25,18 +33,25 @@ typedef long double gnum_float;
#define GNUM_FORMAT_f "Lf"
#define GNUM_FORMAT_g "Lg"
#define GNUM_DIG LDBL_DIG
#define GNUM_MANT_DIG LDBL_MANT_DIG
#define GNUM_MAX_EXP LDBL_MAX_EXP
#define GNUM_MAX LDBL_MAX
#else /* !WITH_LONG_DOUBLE */
typedef double gnum_float;
#define strtognum strtod
#define modfgnum modf
#define gnumabs fabs
#define GNUM_FORMAT_e "e"
#define GNUM_FORMAT_E "E"
#define GNUM_FORMAT_f "f"
#define GNUM_FORMAT_g "g"
#define GNUM_DIG DBL_DIG
#define GNUM_MANT_DIG DBL_MANT_DIG
#define GNUM_MAX_EXP DBL_MAX_EXP
#define GNUM_MAX DBL_MAX
#endif
......
......@@ -122,7 +122,7 @@ range_avedev (const gnum_float *xs, int n, gnum_float *res)
range_average (xs, n, &m);
for (i = 0; i < n; i++)
s += fabs (xs[i] - m);
s += gnumabs (xs[i] - m);
*res = s / n;
return 0;
} else
......
......@@ -94,8 +94,8 @@ LUPDecomp (gnum_float **A, gnum_float **LU, int *P, int n)
int mov = -1;
for (j = i; j < n; j++)
if (fabs (LU[i][j]) > max) {
max = fabs (LU[i][j]);
if (gnumabs (LU[i][j]) > max) {
max = gnumabs (LU[i][j]);
mov = j;
}
if (max == 0) return 2; /*all 0s; singular*/
......
......@@ -8,6 +8,7 @@
*/
#include <gnumeric-config.h>
#include "gnumeric.h"
#include "numbers.h"
#include "parse-util.h"
#include "solver.h"
......@@ -377,8 +378,10 @@ callback (int iter, gnum_float *x, gnum_float bv, gnum_float cx, int n, void *da
int i;
printf ("Iteration=%3d ", iter + 1);
printf ("bv=%9.4" GNUM_FORMAT_f " cx=%9.4" GNUM_FORMAT_f " gap=%9.4" GNUM_FORMAT_f "\n",
bv, cx, fabs (bv - cx));
printf ("bv=%9.4" GNUM_FORMAT_f
" cx=%9.4" GNUM_FORMAT_f
" gap=%9.4" GNUM_FORMAT_f "\n",
bv, cx, gnumabs (bv - cx));
for (i = 0; i < n; i++)
printf ("%8.4" GNUM_FORMAT_f " ", x[i]);
printf ("\n");
......@@ -1002,13 +1005,13 @@ solver_answer_report (WorkbookControl *wbc, Sheet *sheet, GSList *ov,
cell = sheet_cell_fetch (sheet, tc, tr);
lhs = value_get_as_float (cell->value);
if (fabs (lhs - rhs) < 0.001)
if (gnumabs (lhs - rhs) < 0.001)
set_cell (&dao, 4, row, _("Binding"));
else
set_cell (&dao, 4, row, _("Not Binding"));
/* Set `Slack' column */
set_cell_float (&dao, 5, row, fabs (lhs - rhs));
set_cell_float (&dao, 5, row, gnumabs (lhs - rhs));
/* Go to next row */
++row;
......
......@@ -146,10 +146,10 @@ validation_eval (WorkbookControl *wbc, MStyle const *mstyle,
return VALIDATION_STATUS_VALID;
case VALIDATION_TYPE_AS_INT : {
double dummy;
gnum_float dummy;
if (val->type == VALUE_FLOAT &&
fabs (modf (cell->value->v_float.val, &dummy)) > 1e-10) {
msg = g_strdup_printf (_("'%f' is not an integer"),
gnumabs (modfgnum (cell->value->v_float.val, &dummy)) > 1e-10) {
msg = g_strdup_printf (_("'%" GNUM_FORMAT_f "' is not an integer"),
cell->value->v_float.val);
break;
}
......
......@@ -868,7 +868,7 @@ value_diff (Value const *a, Value const *b)
case VALUE_FLOAT: {
const gnum_float da = value_get_as_float (a);
const gnum_float db = value_get_as_float (b);
return fabs (da - db);
return gnumabs (da - db);
}
default:
return TYPE_MISMATCH;
......
......@@ -3803,8 +3803,8 @@ cb_select_auto_expr (GtkWidget *widget, GdkEventButton *event, Workbook *wbcg)
* WARNING * WARNING * WARNING
*/
static struct {
char *displayed_name;
char *function;
const char *displayed_name;
const char *function;
} const quick_compute_routines [] = {
{ N_("Sum"), "sum(selection(0))" },
{ N_("Min"), "min(selection(0))" },
......@@ -4335,7 +4335,7 @@ wbcg_validation_msg (WorkbookControl *wbc, ValidationStyle v,
{
WorkbookControlGUI *wbcg = (WorkbookControlGUI *)wbc;
ValidationStatus res0, res1 = VALIDATION_STATUS_VALID; /* supress warning */
char *btn0, *btn1;
const char *btn0, *btn1;
GtkMessageType type;
GtkWidget *dialog;
int response;
......
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