Skip to content

Commit

Permalink
Merge pull request #19 from stephen-hill/bcscale
Browse files Browse the repository at this point in the history
Bcscale
  • Loading branch information
stephen-hill authored Jul 20, 2016
2 parents 19d6e29 + d5a7847 commit 75ef712
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/BCMathService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function encode($string)
// The remainder or modulo on each loop becomes a base 58 character
$output = '';
while ($decimal >= $this->base) {
$div = bcdiv($decimal, $this->base);
$div = bcdiv($decimal, $this->base, 0);
$mod = bcmod($decimal, $this->base);
$output .= $this->alphabet[$mod];
$decimal = $div;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function decode($base58)
while ($decimal > 0) {
$byte = bcmod($decimal, 256);
$output = pack('C', $byte) . $output;
$decimal = bcdiv($decimal, 256);
$decimal = bcdiv($decimal, 256, 0);
}

// Now we need to add leading zeros
Expand Down
3 changes: 2 additions & 1 deletion tests/Base58Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function encodingsProvider()
array('simply a long string', '2cFupjhnEsSn59qHXstmK2ffpLv2'),
array("\x00\x61", '12g'),
array("\x00", '1'),
array("\x00\x00", '11')
array("\x00\x00", '11'),
array('0248ac9d3652ccd8350412b83cb08509e7e4bd41', '3PtvAWwSMPe2DohNuCFYy76JhMV3rhxiSxQMbPBTtiPvYvneWu95XaY')
);

$return = array();
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@

require_once 'vendor/autoload.php';
date_default_timezone_set("UTC");

// Setting "bcmath.scale" to something other than 0 so that
// we can be sure bcdiv's $scale parameter is working correctly
bcscale(16);

0 comments on commit 75ef712

Please sign in to comment.