_______ __ __ __ __ __
| \ | \ | \ / \ | \ | \
| $$$$$$$\ \$$ ______ | $$\ / $$ ______ _| $$_ | $$____
| $$__/ $$| \ / \ | $$$\ / $$$ | \| $$ \ | $$ \
| $$ $$| $$| $$$$$$\| $$$$\ $$$$ \$$$$$$\\$$$$$$ | $$$$$$$\
| $$$$$$$\| $$| $$ | $$| $$\$$ $$ $$ / $$ | $$ __ | $$ | $$
| $$__/ $$| $$| $$__| $$| $$ \$$$| $$| $$$$$$$ | $$| \| $$ | $$
| $$ $$| $$ \$$ $$| $$ \$ | $$ \$$ $$ \$$ $$| $$ | $$
\$$$$$$$ \$$ _\$$$$$$$ \$$ \$$ \$$$$$$$ \$$$$ \$$ \$$
| \__| $$
\$$ $$
\$$$$$$
A PHP library to work with big integers. This library makes use of the GMP extension and bcmath to do its calculations.
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!
Via 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'));
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);
-
Simple init Mothod: of(string $value)
-
Support using with pecl Operator overloading extension, there are operators could be used:
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) |
- If without pecl Operator overloading extension, there are mothods of operators could be used:
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)));
//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!
Please see CHANGELOG for more information what has changed recently.
$ composer test
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
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please create an issue in the issue tracker.
The MIT License (MIT). Please see License File for more information.