PHP code example of mocking-magician / mathoraptor
1. Go to this page and download the library: Download mocking-magician/mathoraptor library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mocking-magician / mathoraptor example snippets
<?
use MockingMagician\Mathoraptor\Number\BigNumber;
use MockingMagician\Mathoraptor\Number\BigInteger;
use MockingMagician\Mathoraptor\Number\BigFraction;
use MockingMagician\Mathoraptor\Exceptions\ParseIntegerException;
// float
$bigNumber = BigNumber::fromString('1.2');
// or integer
$bigNumber = BigNumber::fromString('1');
// or strict integer
$bigInteger = BigInteger::fromString('1');
try {
// that throw an error if not integer
$bigInteger = BigInteger::fromString('1.1');
} catch (ParseIntegerException $e) {
}
// fraction
$bigFraction = new BigFraction(BigInteger::fromString('11'), BigInteger::fromString('7'));
// for each number type, available operations are :
// - add
// - sub
// - multiplyBy
// - divideBy
$bigNumber->add($bigInteger); // return a new BigNumber
$bigNumber->sub($bigInteger); // return a new BigNumber
// ... multiplyBy
// ... divideBy
$bigNumber->add($bigFraction); // return a new BigFraction
// ... multiplyBy
// ... divideBy