Commit 394ac408 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Supply these. Use everywhere.

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

	* src/numbers.h (floorgnum, ceilgnum, powgnum, expgnum, loggnum,
	log10gnum, singnum, cosgnum, tangnum, asingnum, acosgnum,
	atangnum): Supply these.  Use everywhere.

	* configure.in: Check for the above.
parent b616f813
2002-02-22 Morten Welinder <terra@diku.dk>
* src/numbers.h (floorgnum, ceilgnum, powgnum, expgnum, loggnum,
log10gnum, singnum, cosgnum, tangnum, asingnum, acosgnum,
atangnum): Supply these. Use everywhere.
* configure.in: Check for the above.
2002-02-22 Morten Welinder <terra@diku.dk>
* configure.in: Check for ldexpl and frexpl.
......
2002-02-22 Morten Welinder <terra@diku.dk>
* src/numbers.h (floorgnum, ceilgnum, powgnum, expgnum, loggnum,
log10gnum, singnum, cosgnum, tangnum, asingnum, acosgnum,
atangnum): Supply these. Use everywhere.
* configure.in: Check for the above.
2002-02-22 Morten Welinder <terra@diku.dk>
* configure.in: Check for ldexpl and frexpl.
......
2002-02-22 Morten Welinder <terra@diku.dk>
* src/numbers.h (floorgnum, ceilgnum, powgnum, expgnum, loggnum,
log10gnum, singnum, cosgnum, tangnum, asingnum, acosgnum,
atangnum): Supply these. Use everywhere.
* configure.in: Check for the above.
2002-02-22 Morten Welinder <terra@diku.dk>
* configure.in: Check for ldexpl and frexpl.
......
......@@ -72,8 +72,29 @@ 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 fabsl frexpl ldexpl string_to_decimal decimal_to_quadruple)
AC_CHECK_HEADERS(floatingpoint.h)
need_sunmath=no
for ldfunc in fabsl sqrtl expl logl log10l ceill floorl powl sinl cosl tanl asinl acosl atanl; do
AC_CHECK_FUNC($ldfunc,
,
AC_CHECK_LIB(sunmath,
$ldfunc,
[ if test "$need_sunmath" = "no"; then
# FIXME: better idea?
LDFLAGS="$LDFLAGS -L/opt/SUNWspro/lib -R/opt/SUNWspro/lib -lsunmath"
sunmathinclude=`ls -d /opt/SUNWspro/*/include/cc | tail -1`
CPPFLAGS="$CPPFLAGS -I$sunmathinclude"
fi
need_sunmath=yes ],
AC_MSG_ERROR([Long doubles require the $ldfunc function.]),
-L/opt/SUNWspro/lib $GNUMERIC_LIBS))
done
if test "$need_sunmath" = "yes"; then
AC_CHECK_HEADERS([sunmath.h floatingpoint.h],
,
AC_MSG_ERROR([Long doubles require the sunmath.h header.]))
fi
AC_CHECK_FUNCS(modfl frexpl ldexpl strtold string_to_decimal decimal_to_quadruple)
if test "$ac_cv_func_strtold" = "yes"; then
true
......
......@@ -12,6 +12,7 @@
#include <math.h>
#include "func.h"
#include "numbers.h"
#include "mathfunc.h"
#include "plugin.h"
#include "value.h"
......@@ -43,14 +44,14 @@ calc_N (gnum_float x)
static gnum_float
calc_d1 (gnum_float X, gnum_float S, gnum_float stddev, gnum_float t, gnum_float r)
{
return (log (S / X) + r * t) / (stddev * sqrt (t))
+ stddev * sqrt (t) / 2.0;
return (loggnum (S / X) + r * t) / (stddev * sqrtgnum (t))
+ stddev * sqrtgnum (t) / 2.0;
}
static gnum_float
calc_d2 (gnum_float X, gnum_float S, gnum_float stddev, gnum_float t, gnum_float r)
{
return calc_d1 (X, S, stddev, t, r) - stddev * sqrt (t);
return calc_d1 (X, S, stddev, t, r) - stddev * sqrtgnum (t);
}
static Value *
......@@ -74,7 +75,7 @@ func_opt_bs_call (FunctionEvalInfo *ei, Value *argv [])
d1 = calc_d1 (X, S, stddev, t, r);
d2 = calc_d2 (X, S, stddev, t, r);
C = S * calc_N (d1) - X * exp (-r * t) * calc_N (d2);
C = S * calc_N (d1) - X * expgnum (-r * t) * calc_N (d2);
return value_new_float (C);
}
......@@ -100,7 +101,7 @@ func_opt_bs_put (FunctionEvalInfo *ei, Value *argv [])
d1 = calc_d1 (X, S, stddev, t, r);
d2 = calc_d2 (X, S, stddev, t, r);
P = -S * calc_N (-d1) + X * exp (-r * t) * calc_N (-d2);
P = -S * calc_N (-d1) + X * expgnum (-r * t) * calc_N (-d2);
return value_new_float (P);
}
......@@ -145,8 +146,8 @@ func_opt_bs_call_theta (FunctionEvalInfo *ei, Value *argv[])
d1 = calc_d1 (X, S, stddev, t, r);
d2 = calc_d2 (X, S, stddev, t, r);
theta = -(S * stddev * calc_Np (d1)) / (2.0 * sqrt (t))
-(r * X * calc_N (d2) * exp (-r * t));
theta = -(S * stddev * calc_Np (d1)) / (2.0 * sqrtgnum (t))
-(r * X * calc_N (d2) * expgnum (-r * t));
return value_new_float (theta);
}
......@@ -169,7 +170,7 @@ func_opt_bs_call_rho (FunctionEvalInfo *ei, Value *argv[])
return value_new_error (ei->pos, gnumeric_err_NUM);
d2 = calc_d2 (X, S, stddev, t, r);
return value_new_float (t * X * exp (-r * t) * calc_N (d2));
return value_new_float (t * X * expgnum (-r * t) * calc_N (d2));
}
static Value *
......@@ -213,7 +214,7 @@ func_opt_bs_put_theta (FunctionEvalInfo *ei, Value *argv[])
d1 = calc_d1 (X, S, stddev, t, r);
d2 = calc_d2 (X, S, stddev, t, r);
theta = - (S * stddev * calc_Np (d1)) / (2.0 * sqrt (t)) + r * X * exp (-r * t) * calc_N (-d2);
theta = - (S * stddev * calc_Np (d1)) / (2.0 * sqrtgnum (t)) + r * X * expgnum (-r * t) * calc_N (-d2);
return value_new_float (theta);
}
......@@ -237,7 +238,7 @@ func_opt_bs_put_rho (FunctionEvalInfo *ei, Value *argv[])
return value_new_error (ei->pos, gnumeric_err_NUM);
d2 = calc_d2 (X, S, stddev, t, r);
return value_new_float (-t * X * exp (-r * t) * calc_N (-d2));
return value_new_float (-t * X * expgnum (-r * t) * calc_N (-d2));
}
static Value *
......@@ -260,7 +261,7 @@ func_opt_bs_gamma (FunctionEvalInfo *ei, Value *argv[])
return value_new_error (ei->pos, gnumeric_err_NUM);
d1 = calc_d1 (X, S, stddev, t, r);
return value_new_float (calc_Np (d1) / (S * stddev * sqrt (t)));
return value_new_float (calc_Np (d1) / (S * stddev * sqrtgnum (t)));
}
static Value *
......@@ -282,10 +283,10 @@ func_opt_bs_vega (FunctionEvalInfo *ei, Value *argv[])
return value_new_error (ei->pos, gnumeric_err_NUM);
d1 = calc_d1 (X, S, stddev, t, r);
return value_new_float (S * sqrt (t) * calc_Np (d1));
return value_new_float (S * sqrtgnum (t) * calc_Np (d1));
}
static char *help_opt_bs_call = {
static const char *help_opt_bs_call = {
N_("@FUNCTION=opt_bs_call\n"
"@SYNTAX=opt_bs_call(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -305,7 +306,7 @@ static char *help_opt_bs_call = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_put = {
static const char *help_opt_bs_put = {
N_("@FUNCTION=opt_bs_put\n"
"@SYNTAX=opt_bs_put(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -325,7 +326,7 @@ static char *help_opt_bs_put = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_call_delta = {
static const char *help_opt_bs_call_delta = {
N_("@FUNCTION=opt_bs_call_delta\n"
"@SYNTAX=opt_bs_call_delta(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -348,7 +349,7 @@ static char *help_opt_bs_call_delta = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_put_delta = {
static const char *help_opt_bs_put_delta = {
N_("@FUNCTION=opt_bs_put_delta\n"
"@SYNTAX=opt_bs_put_delta(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -371,7 +372,7 @@ static char *help_opt_bs_put_delta = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_call_rho = {
static const char *help_opt_bs_call_rho = {
/* xgettext:no-c-format */
N_("@FUNCTION=opt_bs_call_rho\n"
"@SYNTAX=opt_bs_call_rho(strike,price,volatility,days_to_maturity,rate)\n"
......@@ -395,7 +396,7 @@ static char *help_opt_bs_call_rho = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_put_rho = {
static const char *help_opt_bs_put_rho = {
/* xgettext:no-c-format */
N_("@FUNCTION=opt_bs_put_rho\n"
"@SYNTAX=opt_bs_put_rho(strike,price,volatility,days_to_maturity,rate)\n"
......@@ -419,7 +420,7 @@ static char *help_opt_bs_put_rho = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_call_theta = {
static const char *help_opt_bs_call_theta = {
N_("@FUNCTION=opt_bs_call_theta\n"
"@SYNTAX=opt_bs_call_theta(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -442,7 +443,7 @@ static char *help_opt_bs_call_theta = {
"opt_bs_put_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_put_theta = {
static const char *help_opt_bs_put_theta = {
N_("@FUNCTION=opt_bs_put_theta\n"
"@SYNTAX=opt_bs_put_theta(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -465,7 +466,7 @@ static char *help_opt_bs_put_theta = {
"opt_bs_call_theta, opt_bs_vega, opt_bs_gamma")
};
static char *help_opt_bs_gamma = {
static const char *help_opt_bs_gamma = {
N_("@FUNCTION=opt_bs_gamma\n"
"@SYNTAX=opt_bs_gamma(strike,price,volatility,days_to_maturity,rate)\n"
"@DESCRIPTION="
......@@ -488,7 +489,7 @@ static char *help_opt_bs_gamma = {
"opt_bs_call_theta, opt_bs_put_rho, opt_bs_vega")
};
static char *help_opt_bs_vega = {
static const char *help_opt_bs_vega = {
/* xgettext:no-c-format */
N_("@FUNCTION=opt_bs_vega\n"
"@SYNTAX=opt_bs_bega(strike,price,volatility,days_to_maturity,rate)\n"
......
......@@ -1033,7 +1033,7 @@ gnumeric_dstdev (FunctionEvalInfo *ei, Value **argv)
if (p.N - 1 == 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (sqrt (p.Q / (p.N - 1)));
return value_new_float (sqrtgnum (p.Q / (p.N - 1)));
}
/***************************************************************************/
......@@ -1102,7 +1102,7 @@ gnumeric_dstdevp (FunctionEvalInfo *ei, Value **argv)
if (p.N == 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (sqrt (p.Q / p.N));
return value_new_float (sqrtgnum (p.Q / p.N));
}
/***************************************************************************/
......
......@@ -54,7 +54,7 @@ val_to_base (FunctionEvalInfo *ei, Value **argv, int num_argv,
if (*err)
return value_new_error (ei->pos, gnumeric_err_NUM);
b10 = pow (src_base, 10);
b10 = powgnum (src_base, 10);
if (v >= b10 / 2) /* N's complement */
v = v - b10;
......@@ -63,12 +63,12 @@ val_to_base (FunctionEvalInfo *ei, Value **argv, int num_argv,
if (v < 0) {
max = 10;
v += pow (dest_base, max);
v += powgnum (dest_base, max);
} else {
if (v == 0)
max = 1;
else
max = (int)(log (v + 0.5) / log (dest_base)) + 1;
max = (int)(loggnum (v + 0.5) / loggnum (dest_base)) + 1;
}
if (places > max)
......
......@@ -63,7 +63,7 @@
static gnum_float
calculate_pvif (gnum_float rate, gnum_float nper)
{
return (pow (1 + rate, nper));
return (powgnum (1 + rate, nper));
}
#if 0
......@@ -76,14 +76,14 @@ calculate_fvif (gnum_float rate, gnum_float nper)
static gnum_float
calculate_pvifa (gnum_float rate, gnum_float nper)
{
return ((1.0 / rate) - (1.0 / (rate * pow (1 + rate, nper))));
return ((1.0 / rate) - (1.0 / (rate * powgnum (1 + rate, nper))));
}
#endif
static gnum_float
calculate_fvifa (gnum_float rate, gnum_float nper)
{
return ((pow (1 + rate, nper) - 1) / rate);
return ((powgnum (1 + rate, nper) - 1) / rate);
}
......@@ -98,8 +98,8 @@ static gnum_float
calculate_principal (gnum_float starting_principal, gnum_float payment,
gnum_float rate, gnum_float period)
{
return (starting_principal * pow (1.0 + rate, period) + payment *
((pow (1 + rate, period) - 1) / rate));
return (starting_principal * powgnum (1.0 + rate, period) + payment *
((powgnum (1 + rate, period) - 1) / rate));
}
static gnum_float
......@@ -804,7 +804,7 @@ gnumeric_effect (FunctionEvalInfo *ei, Value **argv)
if (rate < 0 || nper <= 0)
return value_new_error (ei->pos, _("effect - domain error"));
return value_new_float (pow ((1 + rate / nper), nper) - 1);
return value_new_float (powgnum ((1 + rate / nper), nper) - 1);
}
/***************************************************************************/
......@@ -842,7 +842,7 @@ gnumeric_nominal (FunctionEvalInfo *ei, Value **argv)
if (rate < 0 || nper <= 0)
return value_new_error (ei->pos, _("nominal - domain error"));
return value_new_float (nper * (pow (1 + rate, 1.0 / nper ) - 1 ));
return value_new_float (nper * (powgnum (1 + rate, 1.0 / nper ) - 1 ));
}
......@@ -918,7 +918,7 @@ gnumeric_db (FunctionEvalInfo *ei, Value **argv)
if (cost == 0 || life <= 0 || salvage / cost < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
rate = 1 - pow ((salvage / cost), (1 / life));
rate = 1 - powgnum ((salvage / cost), (1 / life));
rate *= 1000;
rate = floor (rate+0.5) / 1000;
......@@ -1132,7 +1132,7 @@ gnumeric_dollarde (FunctionEvalInfo *ei, Value **argv)
floored = floor (fractional_dollar);
rest = fractional_dollar - floored;
return value_new_float (floored + ((gnum_float) rest * pow (10, n) /
return value_new_float (floored + ((gnum_float) rest * powgnum (10, n) /
fraction));
}
......@@ -1175,7 +1175,7 @@ gnumeric_dollarfr (FunctionEvalInfo *ei, Value **argv)
rest = fractional_dollar - floored;
return value_new_float (floored + ((gnum_float) (rest * fraction) /
pow (10, n)));
powgnum (10, n)));
}
/***************************************************************************/
......@@ -1213,9 +1213,9 @@ gnumeric_mirr (FunctionEvalInfo *ei, Value **argv)
for (i = 0, npv_pos = npv_neg = 0; i < n; i++) {
gnum_float v = values[i];
if (v >= 0)
npv_pos += v / pow (1 + rrate, i);
npv_pos += v / powgnum (1 + rrate, i);
else
npv_neg += v / pow (1 + frate, i);
npv_neg += v / powgnum (1 + frate, i);
}
if (npv_neg == 0 || npv_pos == 0 || rrate <= -1) {
......@@ -1228,8 +1228,8 @@ gnumeric_mirr (FunctionEvalInfo *ei, Value **argv)
* the one Microsoft claims to use and it produces the results
* that Excel does. -- MW.
*/
res = pow ((-npv_pos * pow (1 + rrate, n)) / (npv_neg * (1 + rrate)),
(1.0 / (n - 1))) - 1.0;
res = powgnum ((-npv_pos * powgnum (1 + rrate, n)) / (npv_neg * (1 + rrate)),
(1.0 / (n - 1))) - 1.0;
result = value_new_float (res);
out:
......@@ -1441,9 +1441,9 @@ gnumeric_rate (FunctionEvalInfo *ei, Value **argv)
goal_seek_initialise (&data);
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
-powgnum (DBL_MAX / 1e10, 1.0 / udata.nper) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
powgnum (DBL_MAX / 1e10, 1.0 / udata.nper) - 1);
/* Newton search from guess. */
status = goal_seek_newton (&gnumeric_rate_f, &gnumeric_rate_df,
......@@ -1517,7 +1517,7 @@ irr_npv (gnum_float rate, gnum_float *y, void *user_data)
sum = 0;
for (i = 0; i < n; i++)
sum += values[i] * pow (1 + rate, n - i);
sum += values[i] * powgnum (1 + rate, n - i);
/*
* I changed the formula above by multiplying all terms by (1+r)^n.
......@@ -1541,7 +1541,7 @@ irr_npv_df (gnum_float rate, gnum_float *y, void *user_data)
sum = 0;
for (i = 0; i < n - 1; i++)
sum += values[i] * (n - i) * pow (1 + rate, n - i - 1);
sum += values[i] * (n - i) * powgnum (1 + rate, n - i - 1);
*y = sum;
return GOAL_SEEK_OK;
......@@ -1570,9 +1570,9 @@ gnumeric_irr (FunctionEvalInfo *ei, Value **argv)
goal_seek_initialise (&data);
data.xmin = MAX (data.xmin,
-pow (DBL_MAX / 1e10, 1.0 / p.n) + 1);
-powgnum (DBL_MAX / 1e10, 1.0 / p.n) + 1);
data.xmax = MIN (data.xmax,
pow (DBL_MAX / 1e10, 1.0 / p.n) - 1);
powgnum (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) {
......@@ -1677,7 +1677,7 @@ callback_function_npv (const EvalPos *ep, Value *value, void *closure)
mm->rate = value_get_as_float (value);
} else
mm->sum += value_get_as_float (value) /
pow (1 + mm->rate, mm->num);
powgnum (1 + mm->rate, mm->num);
mm->num++;
return NULL;
}
......@@ -1746,8 +1746,8 @@ gnumeric_xnpv (FunctionEvalInfo *ei, Value **argv)
}
for (i = 0; i < p_n; i++)
sum += payments[i] / pow (1 + rate, (dates[i] - dates[0]) /
365.0);
sum += payments[i] / powgnum (1 + rate, (dates[i] - dates[0]) /
365.0);
result = value_new_float (sum);
out:
......@@ -1812,7 +1812,7 @@ xirr_npv (gnum_float rate, gnum_float *y, void *user_data)
if (d < 0)
return GOAL_SEEK_ERROR;
sum += values[i] / pow (1 + rate, d / 365.0);
sum += values[i] / powgnum (1 + rate, d / 365.0);
}
*y = sum;
......@@ -2080,7 +2080,7 @@ gnumeric_nper (FunctionEvalInfo *ei, Value **argv)
if (tmp <= 0.0)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (log (tmp) / log (1.0 + rate));
return value_new_float (loggnum (tmp) / loggnum (1.0 + rate));
}
/***************************************************************************/
......@@ -2116,7 +2116,7 @@ gnumeric_duration (FunctionEvalInfo *ei, Value **argv)
else if (fv / pv < 0)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (log (fv / pv) / log (1.0 + rate));
return value_new_float (loggnum (fv / pv) / loggnum (1.0 + rate));
}
......@@ -2322,9 +2322,9 @@ gnumeric_price (FunctionEvalInfo *ei, Value **argv)
base = 1.0 + yield / freq;
exponent = d / e;
for (k = 0; k < n; k++)
sum += den / pow (base, exponent + k);
sum += den / powgnum (base, exponent + k);
first_term = redemption / pow (base, (n - 1.0 + d / e));
first_term = redemption / powgnum (base, (n - 1.0 + d / e));
last_term = a / e * den;
result = value_new_float (first_term + sum - last_term);
......@@ -2584,12 +2584,12 @@ gnumeric_oddfprice (FunctionEvalInfo *ei, Value **argv)
*/
/* Odd short first coupon */
term1 = redemption / pow (1.0 + yield / freq, n - 1.0 + ds / e);
term2 = (100.0 * rate / freq * df / e) / pow (1.0 + yield / freq, ds / e);;
term1 = redemption / powgnum (1.0 + yield / freq, n - 1.0 + ds / e);
term2 = (100.0 * rate / freq * df / e) / powgnum (1.0 + yield / freq, ds / e);;
last_term = 100.0 * rate / freq * a / e;
sum = 0;
for (k = 1; k < n; k++)
sum += (100.0 * rate / freq) / pow (1 + yield / freq, k + ds / e);
sum += (100.0 * rate / freq) / powgnum (1 + yield / freq, k + ds / e);
result = value_new_float (term1 + term2 + sum - last_term);
......
......@@ -144,7 +144,7 @@ range_gcd (const gnum_float *xs, int n, gnum_float *res)
if (xs[i] <= 0)
return 1;
else
gcd_so_far = gcd ((int)(floor (xs[i])),
gcd_so_far = gcd ((int)(floorgnum (xs[i])),
gcd_so_far);
}
*res = gcd_so_far;
......@@ -198,7 +198,7 @@ range_lcm (const gnum_float *xs, int n, gnum_float *res)
if (x <= 0)
return 1;
else {
int xi = (int) floor (x);
int xi = (int) floorgnum (x);
lcm_so_far /= gcd (lcm_so_far, xi);
lcm_so_far *= xi;
}
......@@ -275,7 +275,7 @@ gnumeric_acos (FunctionEvalInfo *ei, Value **args)
if ((t < -1.0) || (t > 1.0))
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (acos (t));
return value_new_float (acosgnum (t));
}
/***************************************************************************/
......@@ -337,7 +337,7 @@ gnumeric_asin (FunctionEvalInfo *ei, Value **args)
if ((t < -1.0) || (t > 1.0))
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (asin (t));
return value_new_float (asingnum (t));
}
/***************************************************************************/
......@@ -386,7 +386,7 @@ static const char *help_atan = {
static Value *
gnumeric_atan (FunctionEvalInfo *ei, Value **args)
{
return value_new_float (atan (value_get_as_float (args [0])));
return value_new_float (atangnum (value_get_as_float (args [0])));
}
/***************************************************************************/
......@@ -766,7 +766,7 @@ static const char *help_cos = {
static Value *
gnumeric_cos (FunctionEvalInfo *ei, Value **argv)
{
return value_new_float (cos (value_get_as_float (argv [0])));
return value_new_float (cosgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
......@@ -836,7 +836,7 @@ static const char *help_exp = {
static Value *
gnumeric_exp (FunctionEvalInfo *ei, Value **argv)
{
return value_new_float (exp (value_get_as_float (argv [0])));
return value_new_float (expgnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
......@@ -869,12 +869,12 @@ gnumeric_fact (FunctionEvalInfo *ei, Value **argv)
if (x < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
x_is_integer = (x == floor (x));
x_is_integer = (x == floorgnum (x));
if (x > 12 || !x_is_integer) {
gnum_float res = exp (lgamma (x + 1));
gnum_float res = expgnum (lgamma (x + 1));
if (x_is_integer)
res = floor (res + 0.5); /* Round, just in case. */
res = floorgnum (res + 0.5); /* Round, just in case. */
return value_new_float (res);
} else
return value_new_int (fact (x));
......@@ -1012,7 +1012,7 @@ gnumeric_log (FunctionEvalInfo *ei, Value **argv)
if (t <= 0.0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (log (t) / log (base));
return value_new_float (loggnum (t) / loggnum (base));
}
/***************************************************************************/
......@@ -1042,7 +1042,7 @@ gnumeric_ln (FunctionEvalInfo *ei, Value **argv)
if (t <= 0.0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (log (t));
return value_new_float (loggnum (t));
}
/***************************************************************************/
......@@ -1070,8 +1070,8 @@ gnumeric_power (FunctionEvalInfo *ei, Value **argv)
x = value_get_as_float (argv [0]);
y = value_get_as_float (argv [1]);
if ((x > 0) || (x == 0 && y > 0) || (x < 0 && y == floor (y)))
return value_new_float (pow (x, y));
if ((x > 0) || (x == 0 && y > 0) || (x < 0 && y == floorgnum (y)))
return value_new_float (powgnum (x, y));
if (x == 0 && y != 0)
return value_new_error (ei->pos, gnumeric_err_DIV0);
......@@ -1104,7 +1104,7 @@ gnumeric_log2 (FunctionEvalInfo *ei, Value **argv)
if (t <= 0.0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (log (t) / M_LN2);
return value_new_float (loggnum (t) / M_LN2);
}
/***************************************************************************/
......@@ -1133,7 +1133,7 @@ gnumeric_log10 (FunctionEvalInfo *ei, Value **argv)
if (t <= 0.0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (log10 (t));
return value_new_float (log10gnum (t));
}
/***************************************************************************/
......@@ -1387,7 +1387,7 @@ static const char *help_sin = {
static Value *
gnumeric_sin (FunctionEvalInfo *ei, Value **argv)
{
return value_new_float (sin (value_get_as_float (argv [0])));
return value_new_float (singnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
......@@ -1437,7 +1437,7 @@ gnumeric_sqrt (FunctionEvalInfo *ei, Value **argv)
if (x < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (sqrt (x));
return value_new_float (sqrtgnum (x));
}
/***************************************************************************/
......@@ -1648,7 +1648,7 @@ static const char *help_tan = {
static Value *
gnumeric_tan (FunctionEvalInfo *ei, Value **argv)
{
return value_new_float (tan (value_get_as_float (argv [0])));
return value_new_float (tangnum (value_get_as_float (argv [0])));
}
/***************************************************************************/
......@@ -1762,7 +1762,7 @@ gnumeric_even (FunctionEvalInfo *ei, Value **argv)
sign = -1;
number = -number;
}
ceiled = ceil (number);
ceiled = ceilgnum (number);
if (fmod (ceiled, 2) == 0)
if (number > ceiled)
return value_new_int ((int) (sign * (ceiled + 2)));
......@@ -1800,7 +1800,7 @@ gnumeric_odd (FunctionEvalInfo *ei, Value **argv)
sign = -1;
number = -number;
}
ceiled = ceil (number);
ceiled = ceilgnum (number);
if (fmod (ceiled, 2) == 1)
if (number > ceiled)
return value_new_int ((int) (sign * (ceiled + 2)));
......@@ -1940,7 +1940,7 @@ gnumeric_sqrtpi (FunctionEvalInfo *ei, Value **argv)
if (n < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (sqrt (M_PI * n));
return value_new_float (sqrtgnum (M_PI * n));
}
/***************************************************************************/
......@@ -1973,7 +1973,7 @@ gnumeric_randbetween (FunctionEvalInfo *ei, Value **argv)
if (bottom > top)
return value_new_error (ei->pos, gnumeric_err_NUM );
r = bottom + floor ((top + 1.0 - bottom) * random_01 ());
r = bottom + floorgnum ((top + 1.0 - bottom) * random_01 ());
return value_new_int ((int)r);
}
......@@ -2884,7 +2884,7 @@ callback_function_seriessum (const EvalPos *ep, Value *value,
coefficient = value_get_as_float (value);
mm->sum += coefficient * pow (mm->x, mm->n);
mm->sum += coefficient * powgnum (mm->x, mm->n);
mm->n += mm->m;
return NULL;
......
......@@ -533,7 +533,7 @@ gnumeric_negbinomdist (FunctionEvalInfo *ei, Value **argv)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (combin (x + r - 1, r - 1) *
pow (p, r) * pow (1 - p, x));
powgnum (p, r) * powgnum (1 - p, x));
}
/***************************************************************************/
......@@ -698,7 +698,7 @@ gnumeric_fisherinv (FunctionEvalInfo *ei, Value **argv)
gnum_float y;
y = value_get_as_float (argv[0]);
return value_new_float ((exp (2 * y) - 1.0) / (exp (2 * y) + 1.0));
return value_new_float ((expgnum (2 * y) - 1.0) / (expgnum (2 * y) + 1.0));
}
/***************************************************************************/
......@@ -1862,7 +1862,7 @@ gnumeric_confidence (FunctionEvalInfo *ei, Value **argv)
if (size < 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
return value_new_float (-qnorm (x / 2, 0, 1) * (stddev / sqrt (size)));
return value_new_float (-qnorm (x / 2, 0, 1) * (stddev / sqrtgnum (size)));
}
/***************************************************************************/
......@@ -2202,7 +2202,7 @@ gnumeric_fisher (FunctionEvalInfo *ei, Value **argv)