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

Problems with TDIST, TINV, and Related Functions #4167

Open
2 of 11 tasks
fauzie811 opened this issue Sep 21, 2024 · 2 comments
Open
2 of 11 tasks

Problems with TDIST, TINV, and Related Functions #4167

fauzie811 opened this issue Sep 21, 2024 · 2 comments

Comments

@fauzie811
Copy link

fauzie811 commented Sep 21, 2024

This is:

What is the expected behavior?

It should returns: 12.7062047

What is the current behavior?

It returns: 1.8373862310371

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

$calculation = \PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance();

$formula = '=TINV(0.05, 1)';
$result = $calculation->_calculateFormulaValue($formula);

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Not sure.

Which versions of PhpSpreadsheet and PHP are affected?

2.2

@oleibman
Copy link
Collaborator

Confirmed. Calculating this value is done with iterative guesses using the Newton-Raphson method, and we've seen other problems using that method for XIRR. We were able to correct it due to the work of others implementing XIRR in other languages; a cursory search does not reveal similar activity for TINV, so solving this may take a long time.

Also of note - PhpSpreadsheet currently uses the same code for T.INV as TINV, and leaves T.INV.2T unimplemented. In fact, T.INV.2T is supposed to yield the same (hopefully correct) result as TINV, and T.INV needs a new algorithm altogether (and should be marked as unimplemented till we figure out what that is). Similarly, T.DIST.2T, currently unimplemented, should yield the same result as TDIST.

@oleibman
Copy link
Collaborator

It actually looks like TDIST might be at fault rather than TINV. In Excel, =TDIST(1.8373862310371,1,2) evaluates to 0.31703; in PhpSpreadsheet, it evaluates to just about 0.05, which is why TINV thinks that that 1.8... is the answer. If that is the case, this might be an easier problem to solve than I'd feared, since TDIST does not use iterative guessing to come up with its result.

@oleibman oleibman changed the title The TINV formula result is different from MS Excel / LibreOffice when the degrees of freedom is 1 Problems with TDIST, TINV, and Related Functions Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants