MathUtility
Class with helper functions for mathematical calculations
Table of Contents
Methods
- calculateWithParentheses() : string
- Calculates the input with parenthesis levels
- calculateWithPriorityToAdditionAndSubtraction() : float|string
- 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.
- 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) : string
    Parameters
- $string : string
- 
                    Input string, eg "(123 + 456) / 789 - 4 
Tags
Return values
string —Calculated value. Or error string.
calculateWithPriorityToAdditionAndSubtraction()
Calculates the input by +,-,*,/,%,^ with priority to + and -
    public
            static        calculateWithPriorityToAdditionAndSubtraction(string $string) : float|string
    Parameters
- $string : string
- 
                    Input string, eg "123 + 456 / 789 - 4 
Tags
Return values
float|string —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
Return values
bool —Returns TRUE if string is a float
canBeInterpretedAsInteger()
Tests if the input can be interpreted as integer.
    public
            static        canBeInterpretedAsInteger(mixed $var) : bool
    Note: "0" will return true while any other number with a leading 0 (including multiple zeroes) will be false.
Note: Integer casting from objects or arrays is considered undefined and thus will return false.
Parameters
- $var : mixed
- 
                    Any input variable to test 
Tags
Return values
bool —Returns TRUE if string is an integer
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(mixed $theInt, int $min[, int $max = 2000000000 ][, int $defaultValue = 0 ]) : int
    Parameters
- $theInt : mixed
- 
                    Input value - will be cast to int if non-integer value is passed. 
- $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(mixed $value, int $minimum, int $maximum) : bool
    Parameters
- $value : mixed
- 
                    Integer value to check. If not an integer this method always returns false. 
- $minimum : int
- 
                    Lower boundary of the range 
- $maximum : int
- 
                    Upper boundary of the range