MathUtil.php 667 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Util;
  10. /**
  11. * Math util.
  12. *
  13. * @internal
  14. */
  15. final class MathUtil
  16. {
  17. /**
  18. * Cast to signed int 32-bit.
  19. */
  20. public static function toSignedInt32(int $int): int
  21. {
  22. if (\PHP_INT_SIZE === 8) {
  23. $int &= 0xffffffff;
  24. if ($int & 0x80000000) {
  25. return $int - 0x100000000;
  26. }
  27. }
  28. return $int;
  29. }
  30. }