2017 © Pedro Peláez
 

library mathematician

A layer on top of BCMath that deals with fractional calculations

image

sixteenstudio/mathematician

A layer on top of BCMath that deals with fractional calculations

  • Wednesday, January 31, 2018
  • by sixteenstudio
  • Repository
  • 2 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Mathematician

A layer on top of BCMath that deals with fractional calculations, (*1)

Requirements

The BCMath PHP extension needs to be required in order for this to work., (*2)

This package has been developed for PHP 7.0^, (*3)

Usage

Instead of using standard BCMath functions such as bcadd and bcsub, use the math_ functions provided within the package., (*4)

math_add($leftOperand, $rightOperand, $scale): Sixteenstudio\Mathematician\Number, (*5)

math_sub($leftOperand, $rightOperand, $scale): Sixteenstudio\Mathematician\Number, (*6)

math_mul($leftOperand, $rightOperand, $scale): Sixteenstudio\Mathematician\Number, (*7)

math_div($leftOperand, $rightOperand, $scale): Sixteenstudio\Mathematician\Number, (*8)

These functions return an instance of Sixteenstudio\Mathematician\Number, unlike BCMath which returns a string representation of the decimal result of the calculation., (*9)

This allows us to do some neat things like represent certain operations as fractions, which in turn allows us to do things like this far more accurately than the likes of standard float logic or BCMath can handle:, (*10)

(1 / 3) * 3 // Equates to 0.9999999999813, (*11)

bcmul(bcdiv(1, 3, 20), 3, 20) // Equates to 0.99999999999999999997, (*12)

math_mul(math_div(1, 3, 20), 3, 20) // Equates to 1.00000000000000000000, (*13)

If you'd prefer not to use the helpers, you can insantiate the Sixteenstudio\Mathematician\Mathematician class and use the respective functions directly like so:, (*14)

<?php

$mathematician = new \Sixteenstudio\Mathematician\Mathematician();

$addition = $mathematician->add(1, 5, 20);
$subtraction = $mathematician->subtract(1, 5, 20);
$multiplication = $mathematician->multiply(1, 5, 20);
$division = $mathematician->divide(1, 5, 20);

The Versions

31/01 2018

dev-master

9999999-dev

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

0.0.4

0.0.4.0

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

0.0.5

0.0.5.0

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

dev-develop

dev-develop

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

0.0.2

0.0.2.0

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

0.0.3

0.0.3.0

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison

31/01 2018

0.0.1

0.0.1.0

A layer on top of BCMath that deals with fractional calculations

  Sources   Download

by Matthew Collison