Commit 3d470a4c authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Special-case n==1 as per HP's calculator manuals. Seems to agree with

2005-11-07  Morten Welinder  <terra@gnome.org>

	* functions.c (price): Special-case n==1 as per HP's calculator
	manuals.  Seems to agree with Excel's undocumented behaviour.
	(Discovered by Philippe Lelong.)  Avoid potentially expensive
	loop.
parent 891d0e9b
......@@ -23,6 +23,9 @@ Morten:
* Fix issues with new function docs method.
* Fix OO import crash. [#320818.]
Philippe Lelong:
* Fix issue with PRICE (and probably related functions).
--------------------------------------------------------------------------
Gnumeric 1.6.0
......
2005-11-07 Morten Welinder <terra@gnome.org>
* functions.c (price): Special-case n==1 as per HP's calculator
manuals. Seems to agree with Excel's undocumented behaviour.
(Discovered by Philippe Lelong.) Avoid potentially expensive
loop.
2005-10-10 Jody Goldberg <jody@gnome.org>
* Release 1.6.0
......
......@@ -240,20 +240,23 @@ price (GDate *settlement, GDate *maturity, gnm_float rate, gnm_float yield,
gnm_float redemption, GnmCouponConvention const *conv)
{
gnm_float a, d, e, sum, den, basem1, exponent, first_term, last_term;
gint k, n;
int n;
a = coupdaybs (settlement, maturity, conv);
d = coupdaysnc (settlement, maturity, conv);
e = coupdays (settlement, maturity, conv);
n = coupnum (settlement, maturity, conv);
sum = 0.0;
den = 100.0 * rate / conv->freq;
basem1 = yield / conv->freq;
exponent = d / e;
/* FIXME: Eliminate loop. */
for (k = 0; k < n; k++)
sum += den / pow1p (basem1, exponent + k);
if (n == 1)
return (redemption + den) / (1 + exponent * basem1) -
a / e * den;
sum = den * pow1p (basem1, 1 - n - exponent) *
pow1pm1 (basem1, n) / basem1;
first_term = redemption / pow1p (basem1, (n - 1.0 + d / e));
last_term = a / e * den;
......
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