adept-digital/int-utils
Composer 安装命令:
composer require adept-digital/int-utils
包简介
Utilities for emulating WebAssembly 32-bit and 64-bit integer operations in PHP.
关键字:
README 文档
README
Utilities for emulating WebAssembly 32-bit and 64-bit integer operations in PHP. These may be useful for porting an application or library from C, C++, or other languages.
Requirements
This package requires a 64-bit build of PHP 8.4 or later.
There is no dependency on external Composer packages or PHP extensions.
Installation
Install via Composer.
composer require adept-digital/int-utils
Usage
There are two classes with near-identical interfaces:
\AdeptDigital\IntUtils\Int32\AdeptDigital\IntUtils\Int64
The following operations are provided:
add(int $a, int $b): int: Integer addition.sub(int $a, int $b): int: Integer subtraction.mul(int $a, int $b): int: Integer multiplication.div_s(int $a, int $b): int: Signed integer division. 1div_u(int $a, int $b): int: Unsigned integer division.rem_s(int $a, int $b): int: Signed integer modulo. 1rem_u(int $a, int $b): int: Unsigned integer modulo.eq(int $a, int $b): int: Equal comparison. 2eqz(int $a): int: Equals zero test. 2ne(int $a, int $b): int: Not equal comparison. 2lt_s(int $a, int $b): int: Signed less than comparison. 2lt_u(int $a, int $b): int: Unsigned less than comparison.le_s(int $a, int $b): int: Signed less than or equal comparison. 2le_u(int $a, int $b): int: Unsigned less than or equal comparison.gt_s(int $a, int $b): int: Signed greater than comparison. 2gt_u(int $a, int $b): int: Unsigned greater than comparison.ge_s(int $a, int $b): int: Signed greater than or equal comparison. 2ge_u(int $a, int $b): int: Unsigned greater than or equal comparison.and(int $a, int $b): int: Bitwise AND. 1or(int $a, int $b): int: Bitwise OR. 1xor(int $a, int $b): int: Bitwise XOR. 1shl(int $a, int $b): int: Shift left. 2shr_s(int $a, int $b): int: Signed (arithmetic) shift right. 2shr_u(int $a, int $b): int: Unsigned (logical) shift right.rotl(int $a, int $b): int: Rotate left.rotr(int $a, int $b): int: Rotate right.clz(int $a): int: Count leading zeros.ctz(int $a): int: Count trailing zeros.popcnt(int $a): int: Population count.extend8_s(int $a): int: Extend the sign of the least significant 8 bits.extend16_s(int $a): int: Extend the sign of the least significant 16 bits.extend32_s(int $a): int: Extend the sign of the least significant 32 bits. 3
32-bit representation
PHP has no 32-bit integer type, so 32-bit numbers are represented in 64-bit, but are limited to the range of a signed
32-bit integer (-2,147,483,648 to 2,147,483,647). For example, 4,294,967,295 (2**32-1) should be represented as
-1. Using numbers outside this range will cause a RangeException to be thrown, unless assertions are disabled, in
which case the result is undefined.
To correctly format an unsigned 32-bit integer, unset the most significant 32 bits:
use \AdeptDigital\IntUtils\Int32; echo Int32::add(Int32::MAX, 1) & 0xFFFF_FFFF; // output: 2147483648
64-bit representation
PHP has no unsigned integer type, so numbers larger than PHP_INT_MAX will appear to be negative.
To correctly format an unsigned integer, use printf() or sprintf():
use \AdeptDigital\IntUtils\Int64; printf('%u', Int64::add(Int64::MAX, 1)); // output: 9223372036854775808
Contributing
All contributions are welcome. If you would like to work on a new feature, consider creating an issue before starting.
TODO
- Add benchmarks and benchmark on different machines.
- Add alternative implementations (eg: GMP, FFI, custom extension).
- Add feature detection for alternative implementations.
License
Copyright 2025 David Gallagher david@adeptdigital.com.au.
The package is licensed under the GNU Lesser General Public License 3.0 or later.
Footnotes
adept-digital/int-utils 适用场景与选型建议
adept-digital/int-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wrap」 「rotate」 「integer」 「overflow」 「unsigned」 「webassembly」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adept-digital/int-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adept-digital/int-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adept-digital/int-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library for AES Key Wrap algorithm with padding support.
Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)
Validation Rule to ensure a value is within valid Mysql Integer ranges.
A library for manipulating images in PHP.
Converter and wrapping object for a number (float or integer) value
Laravel Integers Hashids Generator. Encode and decode ids to Integers. Also generate prefixed hashids
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2025-08-13