summaryrefslogtreecommitdiffstats
path: root/straight_line_loan.c
diff options
context:
space:
mode:
authorgonzo <gonzo@toniatuh.com>2023-05-19 22:28:10 +0200
committergonzo <gonzo@toniatuh.com>2023-05-19 22:28:10 +0200
commit2c380f8df666fcebd979511f33e7d72291b389cd (patch)
tree0238209fa73cfa7e4c0a8a58b3ffd8426c20db60 /straight_line_loan.c
parent0751b55f611b889f63dfc2bc2705e7537703cb43 (diff)
downloadloan_calc-2c380f8df666fcebd979511f33e7d72291b389cd.tar.gz
moved from floats to doubles for added precision
Diffstat (limited to 'straight_line_loan.c')
-rw-r--r--straight_line_loan.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/straight_line_loan.c b/straight_line_loan.c
index df86dcc..024fd49 100644
--- a/straight_line_loan.c
+++ b/straight_line_loan.c
@@ -1,6 +1,6 @@
#include "loans.h"
-contract *sl_init(int n, int d, float r, float P) {
+contract *sl_init(int n, int d, double r, double P) {
if ((n < 0)) return NULL;
if ((d >= n)||(d < 0)) return NULL;
contract *c = (contract *)calloc(1, sizeof(contract));
@@ -12,11 +12,11 @@ contract *sl_init(int n, int d, float r, float P) {
return c;
}
-float sl_update(contract *c) {
+double sl_update(contract *c) {
if (c->k > c->n)
- return 0.0f;
+ return 0.0;
- if (c->k == c->d) c->D = c->P/(float)(c->n - c->k);
+ if (c->k == c->d) c->D = c->P/(double)(c->n - c->k);
c->k++;
c->I = c->r * c->P;