public static double nper(double r, double y, double p, double f, boolean t) {double retval = 0;if (r == 0) {retval = -1 * (f + p) / y;} else {double r1 = r + 1;double ryr = (t ? r1 : 1) * y / r;double a1 = ((ryr - f) < 0)? Math.log(f - ryr): Math.log(ryr - f);double a2 = ((ryr - f) < 0)? Math.log(-p - ryr): Math.log(p + ryr);double a3 = Math.log(r1);retval = (a1 - a2) / a3;}return retval;}

public static double nper(double r, double y, double p, double f, bool t){double retval = 0;if (r == 0){retval = -1 * (f + p) / y;}else{double r1 = r + 1;double ryr = (t ? r1 : 1) * y / r;double a1 = ((ryr - f) < 0)? Math.Log(f - ryr): Math.Log(ryr - f);double a2 = ((ryr - f) < 0)? Math.Log(-p - ryr): Math.Log(p + ryr);double a3 = Math.Log(r1);retval = (a1 - a2) / a3;}return retval;}
