dev-master
9999999-devA php library to deal with dynamic number systems and conversion
MIT
The Requires
- ext-gmp *
The Development Requires
by Christoph Rosse
system numeric
A php library to deal with dynamic number systems and conversion
This PHP-Library can be used to make simple calculations with dynamic number-systems., (*1)
Number-System can be installed via. Composer:, (*4)
composer require "gries/number-system"
use gries\NumberSystem\HexadecimalSystem; use gries\NumberSystem\Number; require_once __DIR__.'/../vendor/autoload.php'; $number = new Number(15); // the default system is decimal $hexNumber = new Number('FF', new HexadecimalSystem()); echo $number->add($hexNumber)->value(); // 270 (15 + 255) echo $hexNumber->add($number)->value(); // 10E (F + FF)
use gries\NumberSystem\Number; use gries\NumberSystem\NumberSystem; require_once __DIR__.'/../vendor/autoload.php'; $elementalSystem = new NumberSystem(['earth', 'fire', 'air', 'water'], '-'); // diffrent ways of creating a number $number = new Number('fire-earth', $elementalSystem); // 4 $largerNumber = $elementalSystem->buildNumber(['fire', 'air', 'air']); // 26 // define your own number system and number class YoloSystem extends NumberSystem { public function __construct() { parent::__construct(['1337', 'yolo', 'swag'], '¿'); } } class YoloNumber extends Number { public function __construct($value) { parent::__construct($value, new YoloSystem()); } } $foo = new YoloNumber('yolo¿swag¿yolo¿yolo¿yolo¿yolo¿swag'); echo $foo->asDecimalString(); // 1337
You can use the ExpressionConverter
to convert mathematical expressions from one system to another., (*5)
$decimal = new NumberSystem(); $binary = new BinaryNumberSystem(); $converter = new ExpressionConverter(); $decimalExpression = new Expression('(1337 * 7) + sin(5)-2', $decimal); echo $converter->convert($decimalExpression, $binary); // -> (10100111001 * 111) + sin(101)-10
vendor/bin/phpspec run
Feel free to give me feedback/feature-request/bug-reports via. github issues. Or just send me a pull-request :), (*6)
For the full copyright and license information, please view the LICENSE file that was distributed with this source code., (*7)
A php library to deal with dynamic number systems and conversion
MIT
system numeric