bardoqi/bigmath 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bardoqi/bigmath

Composer 安装命令:

composer require bardoqi/bigmath

包简介

A PHP library to work with big integers and big decimals in most easy way.

README 文档

README

_______   __            __       __             __      __       
|       \ |  \          |  \     /  \           |  \    |  \      
| $$$$$$$\ \$$  ______  | $$\   /  $$  ______  _| $$_   | $$____  
| $$__/ $$|  \ /      \ | $$$\ /  $$$ |      \|   $$ \  | $$    \ 
| $$    $$| $$|  $$$$$$\| $$$$\  $$$$  \$$$$$$\\$$$$$$  | $$$$$$$\
| $$$$$$$\| $$| $$  | $$| $$\$$ $$ $$ /      $$ | $$ __ | $$  | $$
| $$__/ $$| $$| $$__| $$| $$ \$$$| $$|  $$$$$$$ | $$|  \| $$  | $$
| $$    $$| $$ \$$    $$| $$  \$ | $$ \$$    $$  \$$  $$| $$  | $$
 \$$$$$$$  \$$ _\$$$$$$$ \$$      \$$  \$$$$$$$   \$$$$  \$$   \$$
              |  \__| $$                                          
               \$$    $$                                          
                \$$$$$$                                           

BigMath

Latest Version on Packagist Software License Total Downloads

A PHP library to work with big integers. This library makes use of the GMP extension and bcmath to do its calculations.

Introduction

Maybe you ara a developer of blockchain using php. Maybe you often coding encrypt and decrypt. And you fund that there is no library easy to use for big integer or high precision number in php. Now you could coding in most easy way with the BigMath!

Install

Via Composer

$ composer require bardoqi/bigmath:dev-master

Usage

    //with pecl Operator overloading extension:
    $number = BInt('8273467836243255543265432745') + BInt('2');
    //without pecl Operator overloading extension:
    $number = BInt('8273467836243255543265432745')->add(BInt('2'));

Features

This library supports the following operations:

  • Big Intgeger and high precision decimal support ....Class BigInteger: using with GMP. ....Class BigDecminal: using with bcmath.

  • Global type converting functions; .... You need not use 'new' operator to create new object. .... You Only need use:

     //to get a new BigInteger instance of $var; 
     BInt($var); 
     //to get a new BigDecimal instance of $var; 
     BDec($var); 
Operator Method
$o + $arg __add($arg)
$o - $arg __sub($arg)
$o * $arg __mul($arg)
$o / $arg __div($arg)
$o % $arg __mod($arg)
$o ** $arg __pow($arg)
$o . $arg __concat($arg)
$o | $arg __bw_or($arg)
$o & $arg __bw_and($arg)
$o ^ $arg __bw_xor($arg)
$o === $arg __is_identical($arg)
$o !== $arg __is_not_identical($arg)
$o == $arg __is_equal($arg)
$o != $arg __is_not_equal($arg)
$o < $arg __is_smaller($arg)
$o <= $arg __is_smaller_or_equal($arg)
$o > $arg __is_greater($arg) *
$o >= $arg __is_greater_or_equal($arg) *
$o <=> $arg __cmp($arg)
++$o __pre_inc()
$o++ __post_inc()
--$o __pre_dec()
$o-- __post_dec()
$o = $arg __assign($arg)
$o += $arg __assign_add($arg)
$o -= $arg __assign_sub($arg)
$o *= $arg __assign_mul($arg)
$o /= $arg __assign_div($arg)
$o %= $arg __assign_mod($arg)
$o **= $arg __assign_pow($arg)
$o |= $arg __assign_bw_or($arg)
$o &= $arg __assign_bw_and($arg)
$o ^= $arg __assign_bw_xor($arg)
Operators method
+ add()
- sub(), substract()
* mul(), multiply()
/ div(), divide()
% mod()
** pow(), power()
++ plus(), increment()
-- minus(), devrement
== eq(), equals()
!= ne(), notEquals()
=== identical()
!== notIdentical(()
> gt(), greaterThan()
>= gte() greaterThanOrEqualsTo()
< lt(), lessThan()
<= lte(), lessThanOrEqualsTo()
<=> cmp(), compareTo()
- negate()
. concat()
  • Mothods for coding simple: max(); min(); even(); odd(); sign(); isOne(); isZero(); randomRange();
  • Mothods of Mathematics: abs(); divideRem; powMod(); squareRoot();
    factorial(); gcd();
  • Mothods for bit orpeator(Only in BigInteger) andBits(); orBits(); clearBits(); complement() invert(); setBit(); testBit(); scan0(); scan1();
  • Mothods of Math Theory(Only in BigInteger) isPrime(); jacobi(); legendre(); perfectSquare() popcount(); root();
  • Chain Operators support: You can just use:
    //with pecl Operator overloading extension:
    $x=($a+$b)*($c-$d);
    //without pecl Operator overloading extension:
    $x=BInt($a)->add(BInt($b))->multiply(BInt($c)->substract(BInt($d))); 		

Sample Code

    //with Operator overloading extension:
    //if sample:
    if(abs($big_g)>abs($big_m)){
        $big_g = $big_g % $big_m;
    }
    
    //while sample:
    While (rt_v!=1){
        $x = $rd_v/$rt_v;
        //...
    }
    
    //for sample:
    for($i=$xstart; $i<$xMax; $i += $step){
        $item = &$data[];
        $item['x']=$i;
    }
    
    //without Operator overloading extension:
    //if sample:
    //if(abs($big_g)>abs($big_m)){...}
    if ($big_g->abs()->gt($big_m->abs())){
        $big_g = $big_g->mod($big_m);
    }
    
    //while sample:
    //While (rt_v!=1){...}
    while (!($rt_v->isOne())){ //rt!=1
        //x=rd/rt
        $x = $rd_v->div($rt_v);
        //...
    }
    
    //for sample:
    //for($i=$xstart; $i<$xMax; $i += $step)
    for($i = BInt($xStart); $i->lt(BInt($xMax)); $i->plus($step)){
        $item = &$data[];
        $item['x']=$i;
    }
    
    //More samples please read the code in exanples! 

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Road Map

Add: '<<' and '>>' Operator to class BigInteger

Add: '~' Operator to class BigInteger

Add: trigonometric functions such as sin cos etc to class BigDecimal

Add: inverse trigonometric function such as asin acos etc to class BigDecimal

Add: hyperbolic trigonometric functions such as sinh cosh etc to class BigDecimal

Add: high precision math constant such as e and pi.

Add: rational number class

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please create an issue in the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固