PHP Class DaveChild\TextStatistics\Maths

Exibir arquivo Open project: nystudio107/seomatic

Protected Properties

Property Type Description
$blnBcmath boolean Efficiency: Is the BC Math extension loaded?

Public Methods

Method Description
bcCalc ( mixed $number1, string $action, mixed $number2, boolean $round = false, integer $decimals, integer $precision = 10 ) : mixed Do simple reliable floating point calculations without the risk of wrong results
normaliseOperator ( string $operator ) : string Normalise operators for bcMath function.
normaliseScore ( integer | float $score, integer $min, integer $max, $dps = 1 ) : integer | float Normalises score according to min & max allowed. If score larger than max, max is returned. If score less than min, min is returned.

Private Methods

Method Description
performCalc ( string | integer | float | boolean $number1, string $action, string | integer | float | boolean $number2, boolean $round, integer $decimals, integer $precision ) : integer | float | boolean Function which performs calculation.

Method Details

bcCalc() public static method

Do simple reliable floating point calculations without the risk of wrong results
See also: http://floating-point-gui.de/
See also: the big red warning on http://php.net/language.types.float.php
public static bcCalc ( mixed $number1, string $action, mixed $number2, boolean $round = false, integer $decimals, integer $precision = 10 ) : mixed
$number1 mixed Scalar (string/int/float/bool)
$action string Calculation action to execute. Valid input: '+' or 'add' or 'addition', '-' or 'sub' or 'subtract', '*' or 'mul' or 'multiply', '/' or 'div' or 'divide', '%' or 'mod' or 'modulus' '=' or 'comp' or 'compare'
$number2 mixed Scalar (string/int/float/bool)
$round boolean Whether or not to round the result. Defaults to false. Will be disregarded for a compare operation
$decimals integer Decimals for rounding operation. Defaults to 0.
$precision integer Calculation precision. Defaults to 10.
return mixed Calculation result or false if either or the numbers isn't scalar or an invalid operation was passed - for compare the result will always be an integer - for all other operations, the result will either be an integer (preferred) or a float

normaliseOperator() public static method

Normalise operators for bcMath function.
public static normaliseOperator ( string $operator ) : string
$operator string Operators such as "+", "add"
return string

normaliseScore() public static method

Also rounds result to specified precision. Thanks to github.com/lvil.
public static normaliseScore ( integer | float $score, integer $min, integer $max, $dps = 1 ) : integer | float
$score integer | float Initial score
$min integer Minimum score allowed
$max integer Maximum score allowed
return integer | float

Property Details

$blnBcmath protected_oe static_oe property

Efficiency: Is the BC Math extension loaded?
protected static bool $blnBcmath
return boolean