This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from precariouspanther/ISSUE-60-float-innerlog…
…10-div-zero ISSUE-60: Fix for division by zero caused by float precision
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Litipk\BigNumbers\Decimal; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class issue60Test extends TestCase | ||
{ | ||
public function test_that_fromFloat_division_does_not_calculate_invalid_log10_avoiding_div_zero() | ||
{ | ||
$value = Decimal::fromFloat(1.001); | ||
$divisor = Decimal::fromFloat(20); | ||
|
||
$this->assertEquals(0.05005, $value->div($divisor)->asFloat()); | ||
$this->assertEquals(0.000434077479319, $value->log10()->asFloat()); | ||
} | ||
|
||
public function test_that_fromFloat_less_than_1_still_correct() | ||
{ | ||
$value = Decimal::fromFloat(0.175); | ||
$divisor = Decimal::fromFloat(20); | ||
|
||
$this->assertEquals(0.009, $value->div($divisor)->asFloat()); | ||
$this->assertEquals(-0.7569, $value->log10()->asFloat()); | ||
} | ||
} |