Giter Club home page Giter Club logo

bigmath's Introduction

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

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.

bigmath's People

Contributors

bardoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

royalwang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.