Skip to content

Commit

Permalink
Merge pull request #8 from BenMorel/intdiv
Browse files Browse the repository at this point in the history
Use intdiv() for integer division
  • Loading branch information
kornrunner authored Jul 13, 2022
2 parents c86dc86 + d828482 commit c625656
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/AC.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static function encode(array $value, float $max_value): float {
}

public static function decode(int $value, float $max_value): array {
$quant_r = floor($value / (19 * 19));
$quant_g = floor($value / 19) % 19;
$quant_r = intdiv($value, 19 * 19);
$quant_g = intdiv($value, 19) % 19;
$quant_b = $value % 19;

return [
Expand Down
4 changes: 2 additions & 2 deletions src/Base83.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Base83 {
private const BASE = 83;

public static function encode(int $value, int $length): string {
if (floor($value / (self::BASE ** $length)) != 0) {
if (intdiv($value, self::BASE ** $length) != 0) {
throw new InvalidArgumentException('Specified length is too short to encode given value.');
}

$result = '';
for ($i = 1; $i <= $length; $i++) {
$digit = floor($value / (self::BASE ** ($length - $i))) % self::BASE;
$digit = intdiv($value, self::BASE ** ($length - $i)) % self::BASE;
$result .= self::ALPHABET[$digit];
}
return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Blurhash.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function decode (string $blurhash, int $width, int $height, float
}

$size_info = Base83::decode($blurhash[0]);
$size_y = floor($size_info / 9) + 1;
$size_y = intdiv($size_info, 9) + 1;
$size_x = ($size_info % 9) + 1;

$length = strlen($blurhash);
Expand Down

0 comments on commit c625656

Please sign in to comment.