diff --git a/src/java/org/apache/poi/ss/formula/functions/FinanceLib.java b/src/java/org/apache/poi/ss/formula/functions/FinanceLib.java index 19a7510c68..dc4917f5e2 100644 --- a/src/java/org/apache/poi/ss/formula/functions/FinanceLib.java +++ b/src/java/org/apache/poi/ss/formula/functions/FinanceLib.java @@ -74,17 +74,14 @@ public final class FinanceLib { * @param t type (true=pmt at beginning of period, false=pmt at end of period) */ public static double fv(double r, double n, double y, double p, boolean t) { - double retval = 0; if (r == 0) { - retval = -1*(p+(n*y)); - } - else { + return -1*(p+(n*y)); + } else { double r1 = r + 1; - retval =((1-Math.pow(r1, n)) * (t ? r1 : 1) * y ) / r + return ((1-Math.pow(r1, n)) * (t ? r1 : 1) * y ) / r - p*Math.pow(r1, n); } - return retval; } /** @@ -99,17 +96,14 @@ public final class FinanceLib { * @param t type (true=pmt at beginning of period, false=pmt at end of period) */ public static double pv(double r, double n, double y, double f, boolean t) { - double retval = 0; if (r == 0) { - retval = -1*((n*y)+f); - } - else { + return -1*((n*y)+f); + } else { double r1 = r + 1; - retval =(( ( 1 - Math.pow(r1, n) ) / r ) * (t ? r1 : 1) * y - f) + return (( ( 1 - Math.pow(r1, n) ) / r ) * (t ? r1 : 1) * y - f) / Math.pow(r1, n); } - return retval; } /** @@ -125,8 +119,8 @@ public final class FinanceLib { double npv = 0; double r1 = r + 1; double trate = r1; - for (int i=0, iSize=cfs.length; i