Skip to content

Commit

Permalink
-0 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krowinski committed Mar 31, 2016
1 parent 6100a32 commit 243be45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BCMathExtended/BC.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static function isNegative($number)
private static function checkNumber($number)
{
$number = str_replace('+', '', filter_var($number, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
if ('' === $number)
if ('' === $number || '-0' === $number)
{
return '0';
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/BCTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function shouldCeil()
self::assertSame('2', BC::ceil(1.8));
self::assertSame('3', BC::ceil(2.7));

self::assertSame('0', BC::ceil('-0'));
self::assertSame('0', BC::ceil(''));
self::assertSame('0', BC::ceil(null));
self::assertSame('20000', BC::ceil('2/0000'));
Expand Down Expand Up @@ -55,6 +56,7 @@ public function shouldFloor()
self::assertSame('1', BC::floor(1.8));
self::assertSame('2', BC::floor(2.7));

self::assertSame('0', BC::floor('-0'));
self::assertSame('0', BC::floor(''));
self::assertSame('0', BC::floor(null));
self::assertSame('20000', BC::floor('2/0000'));
Expand All @@ -76,6 +78,7 @@ public function shouldAbs()
self::assertSame('1.5', BC::abs('-1.5'));
self::assertSame('9999999999999999999999999999999999999999999999999999999', BC::abs('-9999999999999999999999999999999999999999999999999999999'));

self::assertSame('0', BC::abs('-0'));
self::assertSame('0', BC::abs(''));
self::assertSame('0', BC::abs(null));
self::assertSame('20000', BC::abs('2/0000'));
Expand Down Expand Up @@ -125,6 +128,7 @@ public function shouldRound()

self::assertSame('99999999999999999999999999999999999', BC::round('99999999999999999999999999999999999.000000000000000000000'));

self::assertSame('0', BC::round('-0'));
self::assertSame('0', BC::round(''));
self::assertSame('0', BC::round(null));
self::assertSame('20000', BC::round('2/0000'));
Expand Down

0 comments on commit 243be45

Please sign in to comment.