Bugs
- From: Vladimir Vuksan <vuksan cs unm edu>
- To: gnome-list gnome org
- Subject: Bugs
- Date: Sat, 13 Mar 1999 21:31:09 -0700 (MST)
1) Copying cells between two GNUMeric files
If I try and copy & paste cells from one worksheet (file) to another I
can't do it :-(.
2) Attached are some files I have been working and have a really bizarre
bug that has occured on two different computer. Please replace
fn-financial.c with the one attached. Compile the code and than load
sample.gnumeric
Change cell D1 to say 1/(C4*C2) since previous reported bug removes
parens.
Look in
B13
It should be 100 but I get 99.0 ?! B13 divides C10 and E1.
Can someone else reproduce it ?
3) Cells not refreshed when cell format changed
To reproduce put in some number in a cell. Click Cell Format and change
formatting. The format in the cell will not change.
sample.gnumeric
/*
* fn-financial.c: Built in financial functions and functions registration
*
* Author:
* Vladimir Vuksan (vuksan@veus.hr)
*/
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"
double calculate_pvif (double rate, int nper);
double calculate_pvifa (double rate, int nper);
/* Some forward declarations */
/*
Function that returns present value interest factor for annuities.
Used both for PV and FV since FVIFA is reciprocal to PVIFA
1
PVIF = ( ---------- ) ^ n
1 + k
1 1
PVIFA = --- - -----------
k k*(1+k)^n
(1+k)^n - 1
FVIFA = ----------------
k
*/
double calculate_pvif (double rate, int nper)
{
return ( pow ( 1 + rate, nper) );
}
double calculate_pvifa (double rate, int nper)
{
return ( ( 1 / rate ) - ( 1 / ( rate * pow(1+rate, nper) ))) ;
}
double calculate_fvifa (double rate, int nper)
{
return ( (pow(1+rate, nper) - 1) / rate);
}
static char *help_effect = {
N_("@FUNCTION=EFFECT\n"
"@SYNTAX=EFFECT(b1,b2)\n"
"@DESCRIPTION=Calculates the effective interest rate from "
"given nominal rate.\n"
"Effective interest rate is:\n"
"\n"
" r"
"( 1 + ------ ) ^ nper - 1"
" nper"
"\n"
"where:\n""
"
"r = nominal interest rate (yearly stated)"
"nper = number of periods used for compounding"
"\n"
"@SEEALSO=NOMINAL")
};
/*
Nominal rate
= nper * [ pow(eff-1, 1/nper) - 1 ]
*/
static Value *
gnumeric_effect (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
double rate;
int nper;
rate = value_get_as_double (argv [0]);
nper = value_get_as_int (argv [1]);
/*
*/
/* Rate or number of periods cannot be negative */
if ( (rate < 0) || (nper < 0) ){
*error_string = _("effect - domain error");
return NULL;
}
return value_float ( pow( (1 + rate/nper) , nper) - 1 );
}
static char *help_sln = {
N_("@FUNCTION=SLN\n"
"@SYNTAX=SLN(cost,salvage value,life)\n"
"@DESCRIPTION=Calculates the straight line depriciation for an"
"asset based on its cost, salvage value and anticipated life."
"\n"
"Formula for it is:"
"\n"
"Depriciation expense = ( cost - salvage value ) / life"
"@SEEALSO=")
};
static Value *
gnumeric_sln (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
double cost,salvage_value,life;
cost = value_get_as_double (argv [0]);
salvage_value = value_get_as_int (argv [1]);
life = value_get_as_double (argv [2]);
/*
Straight line depriciation is
cost - salvage_value
depriciation expense = ----------------------------
life (in years)
where
cost = cost of an asset when acquired (market value)
salvage_value = amount you get when asset sold at the end of life
life = anticipated life of an asset
*/
/* Life of an asset cannot be negative */
if ( life < 0 ){
*error_string = _("sln - domain error");
return NULL;
}
return value_float ( (cost - salvage_value) / life ) ;
}
static char *help_syd = {
N_("@FUNCTION=SYD\n"
"@SYNTAX=SYD(cost,salvage value,life,period)\n"
"@DESCRIPTION=Calculates the sum-of-years digits depriciation for an"
"asset based on its cost, salvage value, anticipated life and a"
"particular period."
"\n"
"Formula for it is:"
"\n"
"Depriciation expense = ( cost - salvage value ) * (life-period+1) * 2 / life * (life + 1)"
"@SEEALSO=SLN")
};
static Value *
gnumeric_syd (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
double cost,salvage_value,life,period;
cost = value_get_as_double (argv [0]);
salvage_value = value_get_as_int (argv [1]);
life = value_get_as_double (argv [2]);
period = value_get_as_double (argv [3]);
return value_float ( ( (cost - salvage_value) * (life-period+1) * 2 ) / ( life * (life + 1) )) ;
}
static char *help_pv = {
N_("@FUNCTION=PV\n"
"@SYNTAX=PV(rate,nper,pmt,fv,type)\n"
"@DESCRIPTION=Calculates the present value of an investment."
"@SEEALSO=FV")
};
static Value *
gnumeric_pv (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
double rate,pmt,fv;
int nper,type;
double pvifa;
rate = value_get_as_double (argv [0]);
nper = value_get_as_int (argv [1]);
pmt = value_get_as_double (argv [2]);
fv = value_get_as_double (argv [3]);
type = value_get_as_int (argv [4]);
/*
PV of a stream of payments is
PV = PVIFA * PMT
*/
/* Calculate the PVIFA */
pvifa = calculate_pvifa(rate,nper);
if ( type == 1 )
pvifa = pvifa * ( 1 + rate);
return value_float ( pvifa * pmt );
}
static char *help_pmt = {
N_("@FUNCTION=PMT\n"
"@SYNTAX=PMT(rate,nper,pv,fv)\n"
"@DESCRIPTION=Calculates the present value of an investment."
"@SEEALSO=PPMT")
};
static Value *
gnumeric_pmt (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
double rate,pv,fv;
int nper;
double pvifa;
rate = value_get_as_double (argv [0]);
nper = value_get_as_int (argv [1]);
pv = value_get_as_double (argv [2]);
fv = value_get_as_double (argv [3]);
/*
PMT = PV / PVIFA
*/
/* Calculate the PVIFA */
pvifa = calculate_pvifa(rate,nper);
return value_float ( pv / pvifa );
}
FunctionDefinition finance_functions [] = {
{ "effect", "ff", "number1,number2", &help_effect, NULL, gnumeric_effect},
{ "sln", "fff", "cost,salvagevalue,life", &help_sln, NULL, gnumeric_sln},
{ "syd", "ffff", "cost,salvagevalue,life,period", &help_syd, NULL, gnumeric_syd},
{ "pv", "fiffi", "rate,nper,pmt,fv,type", &help_pv, NULL, gnumeric_pv},
{ "pmt", "ffff", "rate,nper,pv,fv", &help_pmt, NULL, gnumeric_pmt}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]