Git Product home page Git Product logo

math's Introduction

PHP Math library

PHP library for arbitrary precision mathematics.

Installation

composer require maba/math

Why

var_dump(intval(9223372036854775807 + 1));
// int(-9223372036854775808)

var_dump(5.2 * 3 === 15.6);
// bool(false)

var_dump((8 + 92233720368547750) * 1500 / 1500 - 92233720368547750);
// float(16)

Usage

use Maba\Component\Math\BcMath;
use Maba\Component\Math\Math;
use Maba\Component\Math\NumberFormatter;

$basicMathImplementation = new BcMath();
$math = new Math($basicMathImplementation);

var_dump($math->add('9223372036854775807', '1'));
// string(40) "9223372036854775808.00000000000000000000"
var_dump($math->isEqual($math->mul('5.2', '3'), '15.6'));
// bool(true)
var_dump($math->sub($math->div($math->mul($math->add('8', '92233720368547750'), '1500'), '1500'), '92233720368547750'));
// string(22) "8.00000000000000000000"

$result = $math->pow($math->mul('3.141592653589793', '2.71828182845904523536'), 13);

$formatter = new NumberFormatter($math);
echo $formatter->formatNumber($result, 4, '.', ' '); // prints 1 284 625 710 591.2256

BcMath class uses bcmath functions. If you need to use some other arbitrary precision math implementation, implement BasicMathInterface.

Running tests

Travis status Coverage Status

composer install
vendor/bin/phpunit

math's People

Contributors

mariusbalcytis avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.