2017 © Pedro Peláez
 

library number-system

A php library to deal with dynamic number systems and conversion

image

gries/number-system

A php library to deal with dynamic number systems and conversion

  • Saturday, January 10, 2015
  • by gries
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Number-System

This PHP-Library can be used to make simple calculations with dynamic number-systems., (*1)

SensioLabsInsight, (*2)

Build Status, (*3)

Installation

Number-System can be installed via. Composer:, (*4)

composer require "gries/number-system"

Usage

Simple

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)

Custom Number System

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

Converting Mathematical Expressions

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

Current limitations aka todo's

  • No support for negative numbers
  • No support of floating point numbers
  • Division always rounds to 0 because ... no floating point number support ;)

Running the tests

vendor/bin/phpspec run

Contribute!

Feel free to give me feedback/feature-request/bug-reports via. github issues. Or just send me a pull-request :), (*6)

Author

License

For the full copyright and license information, please view the LICENSE file that was distributed with this source code., (*7)

The Versions

10/01 2015

dev-master

9999999-dev

A php library to deal with dynamic number systems and conversion

  Sources   Download

MIT

The Requires

  • ext-gmp *

 

The Development Requires

by Christoph Rosse

system numeric