coquibot/coqui-toolkit-calculator
Composer 安装命令:
composer require coquibot/coqui-toolkit-calculator
包简介
Math calculator toolkit for Coqui — evaluate arithmetic, scientific, and algebraic expressions with batch support
README 文档
README
Math expression evaluator toolkit for Coqui. Provides a token-efficient calculate tool that evaluates arithmetic, scientific, and algebraic expressions — powered by nxp/math-executor with 60+ built-in functions.
Requirements
- PHP 8.4+
Installation
composer require coquibot/coqui-toolkit-calculator
When installed alongside Coqui, the toolkit is auto-discovered via Composer's extra.php-agents.toolkits — no manual registration needed.
Tools Provided
calculate
Evaluate one or more math expressions in a single call.
| Parameter | Type | Required | Description |
|---|---|---|---|
expressions |
string | Yes | Semicolon-delimited math expressions (e.g. 2+3; sin(pi/4); x=5; x^2) |
precision |
string | No | Decimal precision. Default: 10. Use bcmath:N for arbitrary precision. |
Features:
- Batch evaluation — semicolon-delimited expressions evaluated in sequence
- Variable support — assign variables that carry forward within a call (
x=5; 2*x+3) - 60+ built-in functions — trig, logarithmic, rounding, statistics, base conversion
- Per-expression error handling — a bad expression doesn't kill the batch
- BCMath mode — arbitrary precision via
precision: "bcmath:20" - No credentials required — pure PHP computation
Supported Functions
| Category | Functions |
|---|---|
| Arithmetic | +, -, *, /, %, ^ |
| Trigonometric | sin, cos, tan, asin, acos, atan, atan2 |
| Hyperbolic | sinh, cosh, tanh |
| Logarithmic | log (natural), log10, log1p, exp, expm1 |
| Rounding | ceil, floor, round, abs |
| Roots/Power | sqrt, pow, hypot |
| Statistics | min, max, avg, median |
| Conversion | deg2rad, rad2deg, bindec, decbin, hexdec, dechex, octdec, decoct |
| Other | fmod, intdiv, pi, if(cond, true, false) |
| Constants | pi (3.14159...), e (2.71828...) |
Output Format
Single expression — returns the raw result value:
5
Batch expressions — returns a JSON array:
[{"expr":"2+3","result":5},{"expr":"sin(pi/4)","result":0.7071067812},{"expr":"x=10","result":10},{"expr":"x^2","result":100}]
Errors — per-expression error fields without stopping the batch:
[{"expr":"2+3","result":5},{"expr":"1/0","error":"Division by zero"},{"expr":"4*5","result":20}]
Standalone Usage
<?php declare(strict_types=1); use CoquiBot\Toolkits\Calculator\CalculatorToolkit; require __DIR__ . '/vendor/autoload.php'; $toolkit = CalculatorToolkit::fromEnv(); $tool = $toolkit->tools()[0]; // Single expression $result = $tool->execute(['expressions' => '2 + 3']); echo $result->content; // 5 // Batch with variables $result = $tool->execute(['expressions' => 'x=10; y=20; sqrt(x^2 + y^2)']); echo $result->content; // [{"expr":"x=10","result":10},{"expr":"y=20","result":20},{"expr":"sqrt(x^2 + y^2)","result":22.360679775}] // BCMath precision $result = $tool->execute([ 'expressions' => '1/3', 'precision' => 'bcmath:30', ]); echo $result->content; // 0.333333333333333333333333333333
Development
git clone https://github.com/AgentCoqui/coqui-toolkit-calculator.git
cd coqui-toolkit-calculator
composer install
Run tests
./vendor/bin/pest
Static analysis
./vendor/bin/phpstan analyse
License
MIT
coquibot/coqui-toolkit-calculator 适用场景与选型建议
coquibot/coqui-toolkit-calculator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「toolkit」 「math」 「calculator」 「php-agents」 「coqui」 「expression-evaluator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coquibot/coqui-toolkit-calculator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coquibot/coqui-toolkit-calculator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coquibot/coqui-toolkit-calculator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
Partition problem for balanced arrays splitting made easy.
Simple, chainable calculation library.
Easy to use arithmetic operations for decimals in PHP (using BCMath)
Core logic for elegant graphic visualization. Render to SVG, PNG, JPG and Base64.
Mandelbrot set simple PHP Generator.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-08