Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bug 68200 #552

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions poi/src/main/java/org/apache/poi/ss/formula/functions/Rate.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
}

private static double _g_div_gp(double r, double n, double p, double x, double y, double w) {
double t1 = Math.pow(r+1, n);
double t2 = Math.pow(r+1, n-1);
return (y + t1*x + p*(t1 - 1)*(r*w + 1)/r) /
(n*t2*x - p*(t1 - 1)*(r*w + 1)/(Math.pow(r, 2) + n*p*t2*(r*w + 1)/r +
p*(t1 - 1)*w/r));
double t1 = Math.pow(r + 1.0, n);
double t2 = Math.pow(r + 1.0, n - 1.0);
double g = y + t1 * x + p * (t1 - 1.0) * (r * w + 1.0) / r;
double gp = (n * t2 * x
- p * (t1 - 1.0) * (r * w + 1.0) / (Math.pow(r, 2.0))
+ n * p * t2 * (r * w + 1.0) / r
+ p * (t1 - 1.0) * w / r);
return g / gp;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,16 @@ void testBug65988() throws Exception {
assertDouble(fe, cell, "RATE(360.0,6.56,-2000.0)", 0.0009480170844060, 0.000001);
}
}

@Test
void testBug68200() throws Exception {
try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
HSSFCell cell = row.createCell(0);
assertDouble(fe, cell, "RATE(22,30000,20000,-82257625,0,0.1)", 0.35397960290713076, 0.000001);
assertDouble(fe, cell, "RATE(22,10000,10000,-313562750,0,0.1)", 0.5252278265995758, 0.000001);
}
}
}