bardoqi/bigmath

一个用于以最简单方式处理大整数和大十进制数的PHP库。

0.0.2 2020-11-26 15:13 UTC

This package is auto-updated.

Last update: 2024-09-27 00:11:30 UTC


README

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

BigMath

Latest Version on Packagist Software License Total Downloads

一个用于处理大整数的PHP库。此库使用GMP扩展和bcmath来进行计算。

简介

也许你是使用PHP的区块链开发者。也许你经常进行加密和解密编码。你发现PHP中没有易于使用的库来处理大整数或高精度数字。现在你可以用BigMath以最简单的方式编码!

安装

通过Composer

$ composer require bardoqi/bigmath:dev-master

用法

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

特性

此库支持以下操作

  • 大整数和高精度十进制支持 ....BigInteger类:使用GMP。 ....BigDecimal类:使用bcmath。

  • 全局类型转换函数; ....你不需要使用'new'操作符来创建新对象。 ....你只需使用

     //to get a new BigInteger instance of $var; 
     BInt($var); 
     //to get a new BigDecimal instance of $var; 
     BDec($var); 
  • 简单的编码方法:max(); min(); even(); odd(); sign(); isOne(); isZero(); randomRange();
  • 数学方法:abs(); divideRem; powMod(); squareRoot();
    factorial(); gcd();
  • 位运算符方法(仅在大整数中):andBits(); orBits(); clearBits(); complement() invert(); setBit(); testBit(); scan0(); scan1();
  • 数学理论方法(仅在大整数中):isPrime(); jacobi(); legendre(); perfectSquare() popcount(); root();
  • 链式运算符支持:你可以直接使用
    //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))); 		

示例代码

    //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! 

变更日志

请参阅CHANGELOG以获取更多最近更改的信息。

测试

$ composer test

路线图

添加:'<<' 和 '>>' 运算符到BigInteger类

添加:'~' 运算符到BigInteger类

添加:正弦、余弦等三角函数到BigDecimal类

添加:反正弦、反余弦等反三角函数到BigDecimal类

添加:双曲正弦、双曲余弦等双曲三角函数到BigDecimal类

添加:e和π等高精度数学常数。

添加:有理数类

贡献

请参阅CONTRIBUTINGCONDUCT以获取详细信息。

安全

如果你发现任何与安全相关的问题,请在问题跟踪器中创建一个问题。

致谢

许可

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。