gnumeric r16696 - in branches/gnumeric-1-8: . plugins/fn-financial
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16696 - in branches/gnumeric-1-8: . plugins/fn-financial
- Date: Wed, 2 Jul 2008 17:58:51 +0000 (UTC)
Author: mortenw
Date: Wed Jul 2 17:58:51 2008
New Revision: 16696
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16696&view=rev
Log:
2008-07-02 Morten Welinder <terra gnome org>
* functions.c (gnumeric_ddb): Use a sane formula for this. Fix
piles of corner cases. Fixes #541158.
Modified:
branches/gnumeric-1-8/NEWS
branches/gnumeric-1-8/plugins/fn-financial/ChangeLog
branches/gnumeric-1-8/plugins/fn-financial/functions.c
Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS (original)
+++ branches/gnumeric-1-8/NEWS Wed Jul 2 17:58:51 2008
@@ -20,6 +20,7 @@
* Fix phyper hang. [#540211]
* Fix problems with invalid dates in fn-financial. [#540690]
* Fix MATCH problem with singletons. [#540996]
+ * Fix DDB problems. [#541158]
--------------------------------------------------------------------------
Gnumeric 1.8.3
Modified: branches/gnumeric-1-8/plugins/fn-financial/functions.c
==============================================================================
--- branches/gnumeric-1-8/plugins/fn-financial/functions.c (original)
+++ branches/gnumeric-1-8/plugins/fn-financial/functions.c Wed Jul 2 17:58:51 2008
@@ -1024,8 +1024,7 @@
gnumeric_ddb (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float cost, salvage, life, period, factor;
- gnm_float total;
- int i;
+ gnm_float f, prior, dep;
cost = value_get_as_float (argv[0]);
salvage = value_get_as_float (argv[1]);
@@ -1033,19 +1032,27 @@
period = value_get_as_float (argv[3]);
factor = argv[4] ? value_get_as_float (argv[4]) : 2;
- if (life <= 0)
+ if (cost < 0 || salvage < 0 || life <= 0 ||
+ period <= 0 || period > life ||
+ factor <= 0)
return value_new_error_NUM (ei->pos);
- total = 0;
- for (i = 0; i < life - 1; i++) {
- gnm_float period_dep = (cost - total) * (factor / life);
- if (period - 1 == i)
- return value_new_float (period_dep);
- else
- total += period_dep;
+ if (salvage >= cost)
+ return value_new_int (0);
+
+ if (period < 1) {
+ period = 1;
+ if (period > life)
+ return value_new_float (cost - salvage);
}
- return value_new_float (cost - total - salvage);
+ f = factor / life;
+ prior = -cost * pow1pm1 (-f, period - 1);
+ dep = (cost - prior) * f;
+
+ /* Depreciation cannot exceed book value. */
+ dep = MIN (dep, MAX (0, cost - prior - salvage));
+ return value_new_float (dep);
}
/***************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]