PHP Класс DaveChild\TextStatistics\Maths

Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$blnBcmath boolean Efficiency: Is the BC Math extension loaded?

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

bcCalc() публичный статический Метод

Do simple reliable floating point calculations without the risk of wrong results
См. также: http://floating-point-gui.de/
См. также: 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.
Результат 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() публичный статический Метод

Normalise operators for bcMath function.
public static normaliseOperator ( string $operator ) : string
$operator string Operators such as "+", "add"
Результат string

normaliseScore() публичный статический Метод

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
Результат integer | float

Описание свойств

$blnBcmath защищенное статическое свойство

Efficiency: Is the BC Math extension loaded?
protected static bool $blnBcmath
Результат boolean