This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Introduction
Andreu Correa Casablanca edited this page Mar 18, 2015
·
1 revision
Litipk PHP BigNumbers supports PHP 5.3.x, 5.4.x, 5.5.x, and 5.6.,x but also Facebook's HHVM. In any case, we recommend to use the latest PHP versions or HHVM.
You can install this library using Composer.
To install it via Composer, just write in the require block of your composer.json file the following text:
{
"require": {
"litipk/php-bignumbers": "0.7.0"
}
}
<?php
use \Litipk\BigNumbers\Decimal as Decimal;
/**
* There are many ways to create Decimal objects.
*/
$ten = Decimal::fromInteger(10);
$two = Decimal::fromString('2.0');
/**
* At this moment there are few binary operators
* that we can use with Decimal objects:
*/
$twenty = $ten->mul($two);
$fifty = $twenty->add(Decimal::fromFloat(30.));
/**
* There are many unary operators too:
*/
$five = Decimal::fromInteger(-5)->abs();
$five->additiveInverse()->equals(Decimal::fromInteger(-5)); // returns true
/**
* You can check many properties of your numbers:
*/
$zero = Decimal::fromInteger(0);
$zero->isZero(); // Returns true
?>
Because Litipk\BigNumbers is distributed through Composer and follows the PSR-4 standard, it uses classes autoloading. If you don't know how to use it, you should read this section of Composer's documentation.
The public classes in the library are:
-
Decimal
: With this class you can create numbers with arbitrary precision. -
InfiniteDecimal
: With this class you can deal with infinite values. -
NumConstants
: If you need using important numerical constants, this class will help you.
To import a specific class, you must add the following line in the header of your PHP script (Change ClassName
with one of the listed public classes):
use \Litipk\BigNumbers\ClassName as ClassName;