Skip to content

Commit

Permalink
Merge pull request #79 from jkramarz/hotfix/bcmath-scale
Browse files Browse the repository at this point in the history
set number of digits after the decimal place in the result of bc math functions functions
  • Loading branch information
vinkla authored Dec 31, 2016
2 parents 1d32de3 + bd49d84 commit 2f6e33a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function add($a, $b)
return gmp_add($a, $b);
}

return bcadd($a, $b);
return bcadd($a, $b, 0);
}

/**
Expand All @@ -49,7 +49,7 @@ public static function multiply($a, $b)
return gmp_mul($a, $b);
}

return bcmul($a, $b);
return bcmul($a, $b, 0);
}

/**
Expand All @@ -66,7 +66,7 @@ public static function divide($a, $b)
return gmp_div_q($a, $b);
}

return bcdiv($a, $b);
return bcdiv($a, $b, 0);
}

/**
Expand All @@ -83,7 +83,7 @@ public static function pow($base, $exp)
return gmp_pow($base, $exp);
}

return bcpow($base, $exp);
return bcpow($base, $exp, 0);
}

/**
Expand Down Expand Up @@ -117,7 +117,7 @@ public static function comp($a, $b)
return gmp_cmp($a, $b);
}

return bccomp($a, $b);
return bccomp($a, $b, 0);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/HashidsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,15 @@ public function testBigNumberDecode($number, $hash)
$decoded = $hashids->decode($hash);
$this->assertEquals($number, $decoded[0]);
}

/**
* @requires function bcscale
*/
public function testBehaviourForDifferentBCMathAccuracy()
{
bcscale(2);
$hashids = new Hashids('this is my salt', 12);
$encoded = $hashids->encode(1);
$this->assertEquals('DngB0NV05ev1', $encoded);
}
}

0 comments on commit 2f6e33a

Please sign in to comment.