MathUtility

Class with helper functions for mathematical calculations

Table of Contents

Methods

calculateWithParentheses()  : int
Calculates the input with parenthesis levels
calculateWithPriorityToAdditionAndSubtraction()  : int
Calculates the input by +,-,*,/,%,^ with priority to + and -
canBeInterpretedAsFloat()  : bool
Tests if the input can be interpreted as float.
canBeInterpretedAsInteger()  : bool
Tests if the input can be interpreted as integer.
convertToPositiveInteger()  : int
Returns $theInt if it is greater than zero, otherwise returns zero.
forceIntegerInRange()  : int
Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is FALSE then the $defaultValue is applied.
isIntegerInRange()  : bool
Checks whether the given number $value is an integer in the range [$minimum;$maximum]

Methods

calculateWithParentheses()

Calculates the input with parenthesis levels

public static calculateWithParentheses(string $string) : int
Parameters
$string : string

Input string, eg "(123 + 456) / 789 - 4

Tags
see
calculateWithPriorityToAdditionAndSubtraction()
see
ContentObjectRenderer::stdWrap()
Return values
int

Calculated value. Or error string.

calculateWithPriorityToAdditionAndSubtraction()

Calculates the input by +,-,*,/,%,^ with priority to + and -

public static calculateWithPriorityToAdditionAndSubtraction(string $string) : int
Parameters
$string : string

Input string, eg "123 + 456 / 789 - 4

Tags
see
MathUtility::calculateWithParentheses()
Return values
int

Calculated value. Or error string.

canBeInterpretedAsFloat()

Tests if the input can be interpreted as float.

public static canBeInterpretedAsFloat(mixed $var) : bool

Note: Float casting from objects or arrays is considered undefined and thus will return false.

Parameters
$var : mixed

Any input variable to test

Tags
see
http://www.php.net/manual/en/language.types.float.php,

section "Formally" for the notation

Return values
bool

Returns TRUE if string is a float

convertToPositiveInteger()

Returns $theInt if it is greater than zero, otherwise returns zero.

public static convertToPositiveInteger(int $theInt) : int
Parameters
$theInt : int

Integer string to process

Return values
int

forceIntegerInRange()

Forces the integer $theInt into the boundaries of $min and $max. If the $theInt is FALSE then the $defaultValue is applied.

public static forceIntegerInRange(int $theInt, int $min[, int $max = 2000000000 ][, int $defaultValue = 0 ]) : int
Parameters
$theInt : int

Input value

$min : int

Lower limit

$max : int = 2000000000

Higher limit

$defaultValue : int = 0

Default value if input is FALSE.

Return values
int

The input value forced into the boundaries of $min and $max

isIntegerInRange()

Checks whether the given number $value is an integer in the range [$minimum;$maximum]

public static isIntegerInRange(int $value, int $minimum, int $maximum) : bool
Parameters
$value : int

Integer value to check

$minimum : int

Lower boundary of the range

$maximum : int

Upper boundary of the range

Return values
bool

        
On this page

Search results