samsara/fermat
Composer 安装命令:
composer require samsara/fermat
包简介
A library providing math and statistics operations for numbers of arbitrary size.
README 文档
README
This project is unit tested against 8.1, and merges are not accepted unless the tests pass.
Installation
To install, simply require the package using composer:
composer require "samsara/fermat:^2.1"
Or include it in your composer.json file:
{
"require": {
"samsara/fermat": "^2.1"
}
}
The project namespace is Samsara\Fermat\Core\*. You can view the project on Packagist.
Modules
Modules are the namespaces outside of Samsara\Fermat\Core and provide functionality beyond integer, decimal, and rational numbers.
All of these modules depend on the Core namespace, while some depend on each other to various degrees.
Samsara\Fermat\Complex: Provides complex number functionality. NOTE: Imaginary numbers are directly supported byCore. Complex numbers are numbers that have both a real part and an imaginary part.Samsara\Fermat\Coordinates: Provides different coordinate systems that can be used to characterize points and their relations to each other.Samsara\Fermat\Expressions: Provides various expressions, generally algebraic, that can be handled as a function instead of as a value.Samsara\Fermat\LinearAlgebra: Provides for math involving matrices and vectors.Samsara\Fermat\Stats: Provides for math involving statistics and probabilities.
Documentation
The Samsara\Fermat\Core\Numbers factory class provides a way to use the Value classes in Fermat without being as specific as those classes may require. Consider the following code:
<?php use Samsara\Fermat\Core\Core\Numbers; $five = Numbers::make(Numbers::IMMUTABLE, 5); $ten = Numbers::make(Numbers::IMMUTABLE, '10'); echo $five->add($ten); // Prints: "15"
Note that the make() method allows you to provide both an int and a string as the value. In fact, it also allows you to provide a float. The first argument is the specific class that will be used for the value, the second argument is the value itself. The third and fourth arguments are optional and represent the scale (in number of decimal places) and the base of the number respectively. The scale and base arguments will only accept integer values.
If you do not specify a scale value, and you are using the default values, it automatically has a scale of either 10, or the string length of the input value, whichever is greater.
Here is an example of using the factory method to make a value that is in a base other than base10:
<?php use Samsara\Fermat\Core\Core\Numbers; use Samsara\Fermat\Core\Core\Enums\NumberBase; // Value in base5 $five = Numbers::make(Numbers::IMMUTABLE, '10', null, NumberBase::Five); // Value in base10 $ten = Numbers::make(Numbers::IMMUTABLE, '10'); echo $ten->add($five); // Prints: "15" (The sum in base10) echo $five->add($ten); // Prints: "30" (The sum in base5)
You can also use a Fraction and Number together:
<?php use Samsara\Fermat\Core\Core\Values\ImmutableDecimal; use Samsara\Fermat\Core\Core\Values\ImmutableFraction; $five = new ImmutableDecimal(5); $oneQuarter = new ImmutableFraction(1, 4); echo $five->add($oneQuarter); // Prints: "5.25" // The asDecimal() method is called on $oneQuarter echo $oneQuarter->add($five); // Prints: "21/4" // Calls getValue() on $five and instantiates a new ImmutableFraction
You can read the full documentation for Fermat here.
Contributing
Please ensure that pull requests meet the following guidelines:
- New files created in the pull request must have a corresponding unit test file, or must be covered within an existing test file.
- Your merge may not drop the project's test coverage below 80%.
- Your merge may not drop the project's test coverage by MORE than 5%.
- Your merge must pass CI build tests for PHP 8.1.
For more information, please see the section on Contributing
samsara/fermat 适用场景与选型建议
samsara/fermat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.12k 次下载、GitHub Stars 达 65, 最近一次更新时间为 2015 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「math」 「numbers」 「bigint」 「large numbers」 「arbitrary precision」 「trigonometry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samsara/fermat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samsara/fermat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samsara/fermat 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
Validation Rule to ensure a value is within valid Mysql Integer ranges.
gmp-based arbitrary precision operations on currency amounts "XXX.YY"; because floats are BAD for representing money
Partition problem for balanced arrays splitting made easy.
Simple, chainable calculation library.
Easy to use arithmetic operations for decimals in PHP (using BCMath)
统计信息
- 总下载量: 3.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 65
- 点击次数: 20
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2015-10-15