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
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
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
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: 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
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
intforceIntegerInRange()
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