承接 danhunsaker/bcmath 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danhunsaker/bcmath

Composer 安装命令:

composer require danhunsaker/bcmath

包简介

PHP bcmath as a static class, with several enhancements.

README 文档

README

Software License Gitter

Latest Version Build Status Codecov Total Downloads

PHP bcmath as a static class, with several enhancements.

Installation

Use Composer:

composer require danhunsaker/bcmath

Usage

Usage is nearly identical to the bcmath extension functions. The main difference is that the bc prefix is replaced by the Danhunsaker\BC class name (which you can easily alias in your project(s) via use Danhunsaker\BC).

In other words:

There are also some additional convenience methods available, that aren't present in the extension:

  • BC::epow() raises e to the argument's power.
  • BC::fact() calculates the factorial of the argument.
  • BC::intval() truncates the fractional portion of the argument, if any.
  • BC::ln() gives the natural logarithm of the argument.
  • BC::log() gives the base 10 logarithm of the argument (uses ln $val/ln 10).
  • BC::max() returns the largest value in an array (the first argument).
  • BC::min() returns the smallest value in an array (the first argument).
  • BC::modfrac() behaves exactly like BC::mod(), except it will return the fractional part of any remainder as well as the integer part.
  • BC::powfrac() supports fractional exponents, allowing roots other than the square to be calculated.
  • BC::root() is a complement to BC::powfrac(), and is in fact just a convenience wrapper for it.
  • BC::round() rounds a value to a given scale.

Expression Parser

There's also BC::parse(), which lets you write your calculations as expressions instead of method calls. It doesn't (yet) support everything available via method calls, but this is planned for a later release. For the moment, here's a list of which ones are supported, and how to specify each in your expressions:

  • BC::add(a, b) => 'a + b'
  • BC::div(a, b) => 'a / b'
  • BC::div(a, b, 0) => 'a \ b'
  • BC::mod(a, b) => 'a % b'
  • BC::modfrac(a, b) => 'a %% b'
  • BC::mul(BC::div(a, b, 0), b) => 'a \* b'
  • BC::sub(a, BC::mod(a, b)) => 'a -% b'
  • BC::mul(a, b) => 'a * b'
  • BC::pow(a, b) => 'a ** b'
  • BC::powfrac(a, b) => 'a ^ b'
  • BC::sub(a, b) => 'a - b'

There are also some logical expressions available, all of which will return a boolean value (true/false) instead of a number:

  • BC::comp(a, b) == 0 => 'a = b' or 'a == b'
  • BC::comp(a, b) == 1 => 'a > b'
  • BC::comp(a, b) == -1 => 'a < b'
  • BC::comp(a, b) >= 0 => 'a >= b'
  • BC::comp(a, b) <= 0 => 'a <= b'
  • BC::comp(a, b) != 0 => 'a != b' or 'a <> b'
  • a and b => 'a & b' or 'a && b'
  • a or b => 'a | b' or 'a || b'
  • a xor b => 'a ~ b' or 'a ~~ b'

The expression parser recognizes parentheses, so you can use those to group your subexpressions as needed. It also supports variables:

BC::parse('{m} * {x} + {b}', ['m' => 0.5, 'x' => 5, 'b' => 0]);

Need to specify a scale for your expression? No problem, just pass it along in the third parameter:

BC::parse('{m} * {x} + {b}', ['m' => 0.5, 'x' => 5, 'b' => 0], 18);

You can, of course, skip the variable list by passing null as the second argument:

BC::parse('{m} * {x} + {b}', null, 18);

// Any unrecognized variables are assumed to be zero,
// so the above is the same as:

BC::parse('0 * 0 + 0', null, 18);

Contributions

Contributions are welcome at any time on GitHub.

Security issues should be reported directly to Dan Hunsaker via email.

danhunsaker/bcmath 适用场景与选型建议

danhunsaker/bcmath 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.63k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2016 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「bcmath」 「large number」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 danhunsaker/bcmath 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 danhunsaker/bcmath 我们能提供哪些服务?
定制开发 / 二次开发

基于 danhunsaker/bcmath 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 34.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 14
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-15