markbaker/complex-functions
Composer 安装命令:
composer require markbaker/complex-functions
包简介
PHP Library for working with complex numbers as procedural functions
关键字:
README 文档
README
PHP Function Library for working with Complex numbers
The library currently provides the following operations:
- addition
- subtraction
- multiplication
- division
- division by
- division into
together with functions for
- theta (polar theta angle)
- rho (polar distance/radius)
- conjugate
- negative
- inverse (1 / complex)
- cos (cosine)
- acos (inverse cosine)
- cosh (hyperbolic cosine)
- acosh (inverse hyperbolic cosine)
- sin (sine)
- asin (inverse sine)
- sinh (hyperbolic sine)
- asinh (inverse hyperbolic sine)
- sec (secant)
- asec (inverse secant)
- sech (hyperbolic secant)
- asech (inverse hyperbolic secant)
- csc (cosecant)
- acsc (inverse cosecant)
- csch (hyperbolic secant)
- acsch (inverse hyperbolic secant)
- tan (tangent)
- atan (inverse tangent)
- tanh (hyperbolic tangent)
- atanh (inverse hyperbolic tangent)
- cot (cotangent)
- acot (inverse cotangent)
- coth (hyperbolic cotangent)
- acoth (inverse hyperbolic cotangent)
- sqrt (square root)
- exp (exponential)
- ln (natural log)
- log10 (base-10 log)
- log2 (base-2 log)
- pow (raised to the power of a real number)
Installation
composer require markbaker/complex-functions:^1.0
(Requires Composer version 2)
Usage
To create a new complex object, you can provide either the real, imaginary and suffix parts as individual values, or as an array of values passed passed to the constructor; or a string representing the value. e.g
$real = 1.23; $imaginary = -4.56; $suffix = 'i'; $complexObject = new Complex\Complex($real, $imaginary, $suffix);
or
$real = 1.23; $imaginary = -4.56; $suffix = 'i'; $arguments = [$real, $imaginary, $suffix]; $complexObject = new Complex\Complex($arguments);
or
$complexString = '1.23-4.56i'; $complexObject = new Complex\Complex($complexString);
Complex objects are immutable: whenever you call a method or pass a complex value to a function that returns a complex value, a new Complex object will be returned, and the original will remain unchanged. This also allows you to chain multiple methods as you would for a fluent interface (as long as they are methods that will return a Complex result).
Performing Mathematical Operations
To perform mathematical operations with Complex values, you can call the appropriate method against a complex value, passing other values as arguments
$complexString1 = '1.23-4.56i'; $complexString2 = '2.34+5.67i'; $complexObject = new Complex\Complex($complexString1); echo $complexObject->add($complexString2);
or use the static Operation methods
$complexString1 = '1.23-4.56i'; $complexString2 = '2.34+5.67i'; echo Complex\Operations::add($complexString1, $complexString2);
or procedurally, you can pass all values to the appropriate (namespaced) function
$complexString1 = '1.23-4.56i'; $complexString2 = '2.34+5.67i'; echo Complex\add($complexString1, $complexString2);
If you want to perform the same operation against multiple values (e.g. to add three or more complex numbers), then you can pass multiple arguments to any of the operations.
You can pass these arguments as Complex objects, or as an array, or a string that will parse to a complex object.
Using functions
When calling any of the available functions for a complex value, you can either call the relevant method for the Complex object
$complexString = '1.23-4.56i'; $complexObject = new Complex\Complex($complexString); echo $complexObject->sinh();
or use the static Functions methods
$complexString = '1.23-4.56i'; echo Complex\Functions::sinh($complexString);
or you can call the function as you would in procedural code, passing the Complex object as an argument
$complexString = '1.23-4.56i'; $complexObject = new Complex\Complex($complexString); echo Complex\sinh($complexObject);
When called procedurally using the function, or statically, you can pass in the argument as a Complex object, or as an array, or a string that will parse to a complex object.
$complexString = '1.23-4.56i'; echo Complex\sinh($complexString);
In the case of the pow() function (the only implemented function that requires an additional argument) you need to pass both arguments when calling the function procedurally
$complexString = '1.23-4.56i'; $complexObject = new Complex\Complex($complexString); echo Complex\pow($complexObject, 2);
or pass the additional argument when calling the method
$complexString = '1.23-4.56i'; $complexObject = new Complex\Complex($complexString); echo $complexObject->pow(2);
markbaker/complex-functions 适用场景与选型建议
markbaker/complex-functions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.52k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mathematics」 「complex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 markbaker/complex-functions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 markbaker/complex-functions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 markbaker/complex-functions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Class for working with complex numbers
Mathematical functions with strict typing and predictable error handling
Strong type support. For when you absolutely want to know what you are getting
Geo calculations library
PHP parser for mathematical expressions.
PHP parser for mathematical expressions, including elementary functions, variables and implicit multiplication. Also supports symbolic differentiation.
统计信息
- 总下载量: 2.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-29