Class M.Math
Extends
M.Object.
This prototype defines methods for simpler handling of mathematical operations.
Defined in: math.js.
Constructor Attributes | Constructor Name and Description |
---|---|
M.Math()
|
Field Attributes | Field Name and Description |
---|---|
The type of this object.
|
Method Attributes | Method Name and Description |
---|---|
pow(base, exponent)
This method returns the value of the base to the power of the exponent.
|
|
random(min, max)
The method returns a random number within the range given by the min property
and the max property, including the min and max value.
|
|
round(input, type, type)
The method returns rounded version of the given input number.
|
Field Detail
{String}
type
The type of this object.
Method Detail
{Number}
pow(base, exponent)
This method returns the value of the base to the power of the exponent. So e.g.
pow(2, 3) would return '2 to the power of 3' --> 8.
- Parameters:
- base
- {Number} The base.
- exponent
- {Number} The exponent.
- Returns:
- {Number} The result of the operation.
{Number}
random(min, max)
The method returns a random number within the range given by the min property
and the max property, including the min and max value.
A test with 100.000 iterations for random(1, 3) created the following distribution:
- 1: 33.2%
- 2: 33.2%
- 3: 33.6%
- Parameters:
- min
- {Number} The minimal value.
- max
- {Number} The maximal value.
- Returns:
- {Number} The result of the operation.
{Number}
round(input, type, type)
The method returns rounded version of the given input number. There are three
types of rounding available:
- M.FLOOR: Returns the next lower integer, so 2.1 and 2.9 both would return 2.
- M.CEIL: Returns the next higher integer, so 2.1 and 2.9 both would return 3.
- M.ROUND: Returns the nearest integer, so 2.1 would return 2 and 2.9 would return 3.
With the optional third parameter 'decimals', you can specify the number of decimal digits to be
returned. For example round(1.2345, M.FLOOR, 3) would return 1.234. The default for this parameter
is 0.
- Parameters:
- input
- {Number} The input value.
- type
- {String} The type of rounding.
- type
- {Number} The number of decimals (only available for M.ROUND).
- Returns:
- {Number} The result of the operation.