ktsirangelos/math-functions
Composer 安装命令:
composer require ktsirangelos/math-functions
包简介
A set of integer-based mathematical operations (divisors, factorials, prime numbers) with XML formatting support for presenting calculation results.
README 文档
README
The MathFunctions package provides a set of classes for performing various integer-based mathematical operations. It includes functionalities for calculating divisors, factorials, and identifying prime numbers within an array of integers. Additionally, it offers XML formatting for presenting calculation results.
Table of Contents
Requirements
Installation
$ composer require ktsirangelos/math-functions
Running Unit Tests
To run the unit tests for this library:
- Clone the GitHub repository
$ git clone https://github.com/ktsirangelos/math-functions.git
- Install dependencies
$ cd math-functions
$ composer install
- Execute the tests
$ ./vendor/bin/phpunit tests
Usage
Calculating Divisors
To calculate the positive and negative divisors of an integer (excluding 1 and itself), use the calcDivisors() method:
use MathFunctions\IntegerCalculator; $integerCalculator = new IntegerCalculator(); // Example usage with integer 12 $divisors = $integerCalculator->calcDivisors(12); // Expected Output: [-6, -4, -3, -2, 2, 3, 4, 6]
Calculating Factorials
To calculate the factorial of an integer, use the calcFactorial() method:
use MathFunctions\IntegerCalculator; $integerCalculator = new IntegerCalculator(); // Example usage with integer 5 $factorial = $integerCalculator->calcFactorial(5); // Expected Output: 120
Identifying Prime Numbers
To find prime numbers within an array of integers and receive the results in XML format, use the calcPrimeNumbers() method:
use MathFunctions\IntegerCalculator; $integerCalculator = new IntegerCalculator(); // Example usage with an array of integers $primeNumbersXML = $integerCalculator->calcPrimeNumbers([2, 3, 4, 5, 6, 7]); // Expected Output (XML string): // <primeNumbers amount="4"> // <result> // <number>2</number> // <number>3</number> // <number>5</number> // <number>7</number> // </result> // </primeNumbers>
Formatting Calculation Results
You can format calculation results into an XML string using the toXML() method:
use MathFunctions\Utilities\ResultFormatter; $resultFormatter = new ResultFormatter(); // Example usage with an array of even numbers $xmlResult = $resultFormatter->toXML('evenNumbers', [2, 4, 6, 8]); // Expected Output (XML string): // <evenNumbers amount="4"> // <result> // <number>2</number> // <number>4</number> // <number>6</number> // <number>8</number> // </result> // </evenNumbers>
Exceptions
The functions may throw exceptions for invalid inputs. Ensure to catch and handle these exceptions appropriately in your code.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
License
This package is licensed under the MIT License. See the LICENSE file for details.
ktsirangelos/math-functions 适用场景与选型建议
ktsirangelos/math-functions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ktsirangelos/math-functions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ktsirangelos/math-functions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-11