support sqrtpi function

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1900418 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-04-30 08:31:31 +00:00
parent 9eb82c1185
commit e4bd111489
2 changed files with 3 additions and 0 deletions

View File

@ -56,6 +56,8 @@ public class Sqrtpi implements FreeRefFunction {
return ErrorEval.NUM_ERROR;
}
final double result = Math.sqrt(Math.PI * d);
//NumberToTextConverter reduces the precision to what Excel uses internally
//without this conversion, `result` is too precise
return new NumberEval(Double.parseDouble(NumberToTextConverter.toText(result)));
} catch (EvaluationException e) {
return e.getErrorEval();

View File

@ -39,6 +39,7 @@ final class TestSqrtpi {
//https://support.microsoft.com/en-us/office/sqrtpi-function-1fb4e63f-9b51-46d6-ad68-b3e7a8b519b4
@Test
void testBasic() {
//the expected values were observed in my copy of Excel
confirmValue(Arrays.asList(1), 1.77245385090552);
confirmValue(Arrays.asList(2), 2.506628274631);
}