thehappycat / numerictools
PHP project to perform basic numeric operations
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 4
Type:project
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2025-07-29 01:51:30 UTC
README
NumericToolsPHP

A simple project created to handle large numeric operations in PHP!
Just like the normal numeric operations you would usually do, but with numbers of any size.
<?php $integerNumber = Integer::createByInt(1); $smallNumber = Integer::createByString('1'); $largeNumber = Integer::createByString('987654321234567898765432123456789'); // A really large number that as primitive type might throw a number in scientific notation or infinity. $reallyLargeNumber = Integer::createByString('12345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321234567898765432123456789876543212345678987654321');
Operations currently supported
Addition
<?php $a = Integer::createByString('1234567898765432123456789876543212345678987654321'); $b = Integer::createByString('987654321234567898765432123456789'); // $c = 1234567898765433111111111111111111111111111111110 $c = $a->add($b);
Subtraction
<?php $a = Integer::createByString('1234567898765432123456789876543212345678987654321'); $b = Integer::createByString('987654321234567898765432123456789'); // $c = 1234567898765431135802468641975313580246864197532 $c = $a->subtract($b); $a = Integer::createByString('987654321234567898765432123456789'); $b = Integer::createByString('1234567898765432123456789876543212345678987654321'); // $c = -1234567898765431135802468641975313580246864197532 $c = $a->subtract($b);
Multiplication
<?php $a = Integer::createByString('999999999999'); $b = Integer::createByString('789'); // $c = 788999999999211 $c = $a->multiplyBy($b); $a = Integer::createByString('1234567898765432123456789876543212345678987654321'); $b = Integer::createByString('987654321234567898765432123456789'); // $c = 1219326320073159600060966114921506736777910409998442005792202408166072245112635269 $c = $a->multiplyBy($b);
Division
<?php $dividend = Integer::createByString('987654321234567898765432123456789'); $divisor = Integer::createByString('12345678987654321'); // $quotient = 80000000180000000 $quotient = $dividend->divideBy($divisor);
Modulo
<?php $dividend = Integer::createByString("1234567890123456789"); $divisor = Integer::createByString("9876543210"); // $module = 8626543209 $module = $dividend->mod($divisor);
Greater than
<?php $a = Integer::createByString("123456789012345678901234567890"); $b = Integer::createByString("987654321"); // true $comparison = $a->greaterThan($b); $a = Integer::createByString("987654321"); $b = Integer::createByString("123456789012345678901234567890"); // false $comparison = $a->greaterThan($b);
Greater or equal to
<?php $a = Integer::createByString("1500"); $b = Integer::createByString("1492"); // true $comparison = $a->greaterOrEqualTo($b); $a = Integer::createByString("1234567890"); $b = Integer::createByString("1234567890"); // true $comparison = $a->greaterOrEqualTo($b); $a = Integer::createByString("1234"); $b = Integer::createByString("1234567890"); // false $comparison = $a->greaterOrEqualTo($b);