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 division by zero warning #3312

Closed
wants to merge 2 commits into from

Conversation

zakariaejaidi
Copy link

PHP Warning: Division by zero in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php on line 155

This is:

- [ x] a bugfix
- [ ] a new feature
- [ ] refactoring
- [ ] additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change
  • Documentation is updated as necessary

zakariaejaidi and others added 2 commits January 21, 2023 02:24
PHP Warning:  Division by zero in /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php on line 155
@MarkBaker
Copy link
Member

When we implement a bugfix, we always try to create a unit test to verify the original problem and confirm that the bugfix works as expected. Would you be able to create a unit test for this fix?

@@ -160,7 +160,8 @@ public static function presentValue($rate, ...$args)
for ($i = 1; $i <= $countArgs; ++$i) {
// Is it a numeric value?
if (is_numeric($aArgs[$i - 1])) {
$returnValue += $aArgs[$i - 1] / (1 + $rate) ** $i;
$val = (1 + $rate) ** $i;
$returnValue += $val != 0 ? $aArgs[$i - 1] / $val : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$val will always be a float, so why do a loose types comparison here?

@oleibman
Copy link
Collaborator

No update in over a year. Closing.

@oleibman oleibman closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants