- Source:
All of general math functions
Members
(static, constant) EM :number
- Source:
Type:
(static, constant) HALF_PI :number
- Source:
Equal to half of `Math.PI`, specific value is `1.5707963267948966`
Type:
(static, constant) KAPPA :Object
- Source:
Kappa constant, specific value is many values:
arc: `0.5522847498307936`, [sin](https://stackoverflow.com/questions/29022438/): `0.364212423249794`, and in, out, inOut
Type:
(static, constant) PHI :number
- Source:
Type:
(static, constant) PLASTIC :number
- Source:
Type:
(static, constant) SQRT_PI :number
- Source:
Square root of `Math.PI`, specific value is `1.7724538509055159`
Type:
(static, constant) SQRT_TAU :number
- Source:
Square root of `Math_TAU`, specific value is `2.5066282746310002`
Type:
(static, constant) TAU :number
- Source:
Equal to double of `Math.PI`, specific value is `6.283185307179586`
Type:
(static, constant) UPC :number
- Source:
Type:
Methods
(static) adjust(function, num, digitsopt, baseopt) → {number}
- Source:
Adjust decimal of a number
Example
Math.adjust(Math.round, Math.PI, 2);
//3.14
Parameters:
Name |
Type |
Attributes |
Default |
Description |
function |
function
|
|
|
function that adjust number (Ex: Math.round) |
num |
number
|
|
|
|
digits |
number
|
<optional>
|
0
|
|
base |
number
|
<optional>
|
|
|
Returns:
-
Type
-
number
(static) adjust2(function, num, digitsopt, baseopt) → {number}
- Source:
Adjust decimal of a number by digit location and base
Example
Math.adjust2(Math.round, Math.PI, 2);
//3.1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
function |
function
|
|
|
function that adjust number (Ex: Math.round) |
num |
number
|
|
|
|
digits |
number
|
<optional>
|
0
|
|
base |
number
|
<optional>
|
|
|
Returns:
-
Type
-
number
(static) approach(num, min, max) → {number}
- Source:
Not sure, but definitely useful and may act as same as bounce, wrap,...
Example
Math.approach(-1, 0, 5);
//-1
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
max |
number
|
|
Returns:
-
Type
-
number
(static) away(num) → {number}
- Source:
Away from zero
Example
Math.away(Math.PI, 2);
//4
Math.away(5, -1, 2);
//-4
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) bernstein(x, v, n) → {number}
- Source:
Example
Math.bernstein(2, 2, 2);
//4
Parameters:
Name |
Type |
Description |
x |
number
|
|
v |
number
|
|
n |
number
|
|
Returns:
-
Type
-
number
(static) bounce(num, min, max, offsetopt) → {number}
- Source:
Move back and front within range
Example
Math.bounce(-1, 0, 10);
//1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
min |
number
|
|
|
|
max |
number
|
|
|
|
offset |
number
|
<optional>
|
1
|
|
Returns:
-
Type
-
number
(static) cdf(mean, std, num, accuracyopt) → {number}
- Source:
Example
Math.cdf(0, 1, 1);
//0.8413447460685428
Parameters:
Returns:
-
Type
-
number
(static) change(num, min, change, duration) → {number}
- Source:
Change linear
Example
Math.change(0, 50, 150, 1);
//50
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
change |
number
|
|
duration |
number
|
|
Returns:
-
Type
-
number
(static) clamp(num, min, max) → {number}
- Source:
Clamp number within range
Example
Math.clamp(0, 1, 2);
//1
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
max |
number
|
|
Returns:
-
Type
-
number
(static) compare(num1, num2, equalopt, reverseopt, accuracyopt) → {boolean}
- Source:
Compare two numbers
Example
Math.compare(0, 1);
//false
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num1 |
number
|
|
|
|
num2 |
number
|
|
|
|
equal |
boolean
|
<optional>
|
|
Change to true if you want to compare `num1 == num2` |
reverse |
boolean
|
<optional>
|
|
Change to true if you want to compare `num1 > num2` |
accuracy |
number
|
<optional>
|
1
|
Accuracy, or epsilon |
Returns:
-
Type
-
boolean
(static) copy(num1, num2) → {number}
- Source:
Copy sign of `num2` to `num1`
Example
Math.copy(2);
//-1
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) correct(num, epsilonopt) → {number}
- Source:
Attempt to correct rounding off error
Example
Math.correct(Math.sin(Math.PI));
//0
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
epsilon |
number
|
<optional>
|
13
|
Accuracy |
Returns:
-
Type
-
number
(static) cycle(num1, num2) → {number}
- Source:
Sanitized modulus function that always returns in the range [0, num2) rather than (-num2, 0] if num1 is negative
Example
Math.cycle(10, 3);
//1
Math.cycle(4, 7);
//4
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) derivative(num, func, columnsopt, accuracy1opt, accuracy2opt) → {number}
- Source:
Example
Math.derivative(Math.PI, Math.sin);
//-1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
The number to calculate |
func |
function
|
|
|
The function to calculate |
columns |
number
|
<optional>
|
6
|
The higher the more accurate (integer only) |
accuracy1 |
number
|
<optional>
|
1e-15
|
|
accuracy2 |
number
|
<optional>
|
1
|
|
Returns:
-
Type
-
number
(static) discrete(function, num, a, b, gapopt, isLocateopt, digitsopt, baseopt) → {number}
- Source:
Same as `snap` but different a little bit...
Example
Math.discrete(Math.round, 0.5, 0, 1);
//1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
function |
function
|
|
|
function that adjust number (Ex: Math.round) |
num |
number
|
|
|
|
a |
number
|
|
|
|
b |
number
|
|
|
|
gap |
number
|
<optional>
|
1
|
The interval gap of the grid |
isLocate |
boolean
|
<optional>
|
false
|
use adjust by digit location and base if true |
digits |
number
|
<optional>
|
0
|
|
base |
number
|
<optional>
|
10
|
|
Returns:
-
Type
-
number
(static) divisor(num, returnDataopt) → {Array.<number>}
- Source:
Calculate divisor of a number
Example
Math.divisor(9);
//[1, 9, 3]
Parameters:
Name |
Type |
Attributes |
Description |
num |
number
|
|
|
returnData |
array
|
<optional>
|
Array to put data |
Returns:
Unsorted array
-
Type
-
Array.<number>
(static) erf(num, accuracyopt) → {number}
- Source:
Example
Math.erf(1);
//0.8427007929497149
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
accuracy |
number
|
<optional>
|
50
|
|
Returns:
-
Type
-
number
(static) erfc(num, accuracyopt) → {number}
- Source:
Example
Math.erfc(1);
//0.1572992070502851
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
accuracy |
number
|
<optional>
|
50
|
|
Returns:
-
Type
-
number
(static) erfcx(num) → {number}
- Source:
Scaled complementary error function
Example
Math.erfcx(1);
//0.42758357615580705
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) factor(num, returnDataopt) → {Array.<number>}
- Source:
Calculate prime factor of a number
Example
Math.factor(9);
//[3, 3]
Parameters:
Name |
Type |
Attributes |
Description |
num |
number
|
|
|
returnData |
array
|
<optional>
|
Array to put data |
Returns:
-
Type
-
Array.<number>
(static) factorial(num, accuracyopt) → {number}
- Source:
Calculate factorial of number
Example
Math.factorial(4.5);
//52.34277778455353
Parameters:
Name |
Type |
Attributes |
Description |
num |
number
|
|
The number to calculate |
accuracy |
number
|
<optional>
|
|
Returns:
-
Type
-
number
(static) flip(num) → {number}
- Source:
Flip sign of num
Example
Math.flip(2);
//-2
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) fold(type, num) → {number}
- Source:
Example
Math.fold(true, 1);
//1
Parameters:
Name |
Type |
Description |
type |
boolean
|
|
num |
number
|
|
Returns:
-
Type
-
number
(static) gamma(num, accuracyopt) → {number}
- Source:
Gamma function
Example
Math.gamma(2.33);
//1.1881928111058075
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
The number to calculate |
accuracy |
number
|
<optional>
|
7
|
|
Returns:
-
Type
-
number
(static) gcd() → {Array.<number>}
- Source:
Calculate
greatest common divisor
No limit of parameter, but all of them must be number, except final one maybe array if you want to pass return data to that array
Example
Math.gcd(9, 6);
//[3, 1, -1]
Returns:
-
Type
-
Array.<number>
(static) haar(num) → {number}
- Source:
Example
Math.haar(0.25);
//1
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) heaviside(type, num) → {number}
- Source:
Example
Math.heaviside(1, 1);
//1
Parameters:
Name |
Type |
Description |
type |
number
|
when `num == 0`, if `type` is `1`, then return `0`; if `type == 2`, return `1`, else `0.5` |
num |
number
|
|
Returns:
-
Type
-
number
(static) ierf(num) → {number}
- Source:
Example
Math.ierf(1);
//2.4752570126123032
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) ierfc(num) → {number}
- Source:
Example
Math.ierfc(10);
//-387.61380920254567
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) infd(type, num) → {number}
- Source:
Example
Math.infd(true, 1);
//-1
Parameters:
Name |
Type |
Description |
type |
boolean
|
|
num |
number
|
|
Returns:
-
Type
-
number
(static) integral(a, b, func, epsilonopt, iterationopt) → {number}
- Source:
Example
Math.integral(1, 5, Math.sin);
//0.25664012040491363
Parameters:
Name |
Type |
Attributes |
Default |
Description |
a |
number
|
|
|
The begin of interval |
b |
number
|
|
|
The end of interval |
func |
function
|
|
|
The function to calculate |
epsilon |
number
|
<optional>
|
1e-15
|
|
iteration |
number
|
<optional>
|
11
|
|
Returns:
-
Type
-
number
(static) invNorm(num) → {number}
- Source:
Example
Math.invNorm(1);
//3.5005420375954306
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) kelly(num1, num2) → {number}
- Source:
Example
Math.kelly(2, 0.5);
//0.25
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) lcm() → {number}
- Source:
Example
Math.lcm(9, 6);
//18
Returns:
-
Type
-
number
(static) lerp(num, min, max) → {number}
- Source:
Normalize number from 0-1 to specific range
Example
Math.lerp(0.1, 0, 100);
//10
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
max |
number
|
|
Returns:
-
Type
-
number
(static) limit(typeopt, num, func, placesopt, epsilonopt) → {number}
- Source:
Example
Math.limit(0, 2, (x) => {return x / (x - 1)}, 100);
//2
Parameters:
Name |
Type |
Attributes |
Default |
Description |
type |
number
|
<optional>
|
0
|
0: limit, 1: limit left, 2: limit right |
num |
number
|
|
|
The number to calculate |
func |
function
|
|
|
The function to calculate |
places |
number
|
<optional>
|
10
|
|
epsilon |
number
|
<optional>
|
1e-10
|
|
Returns:
-
Type
-
number
(static) ln(num) → {number}
- Source:
Calculate natural logarithm
Example
Math.ln(10);
//2.302585092994046
Parameters:
Name |
Type |
Description |
num |
number
|
The number to calculate |
Returns:
-
Type
-
number
(static) lnGamma(num) → {number}
- Source:
Calculate natural logarithm of gamma function
Example
Math.lnGamma(5.25);
//3.5613759103866967
Parameters:
Name |
Type |
Description |
num |
number
|
The number to calculate |
Returns:
-
Type
-
number
(static) log(num, baseopt) → {number}
- Source:
Calculate logarithm of n base
Example
Math.log(10000, 10);
//4
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
The number to calculate |
base |
number
|
<optional>
|
Math.E
|
The logarithm base |
Returns:
-
Type
-
number
(static) map(num, min1, max1, min2, max2) → {number}
- Source:
Map number from a range to another range
Example
Math.map(0.1, 0, 1, 0, 100);
//10
Parameters:
Name |
Type |
Description |
num |
number
|
|
min1 |
number
|
Current minimum |
max1 |
number
|
Current maximum |
min2 |
number
|
Target minimum |
max2 |
number
|
Target maximun |
Returns:
-
Type
-
number
(static) mod(num1, num2) → {number}
- Source:
Calculate modulo (not remainder) by `num1 % num2`
Example
Math.mod(-21, 4);
//3
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) nCr(num1, num2) → {number}
- Source:
Example
Math.nCr(8, 5);
//56
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) near(num, epsilon) → {number}
- Source:
Nearest increment
Example
Math.near(Math.sin(Math.PI), 0.01);
//0
Parameters:
Name |
Type |
Description |
num |
number
|
|
epsilon |
number
|
|
Returns:
-
Type
-
number
(static) norm(num, min, max) → {number}
- Source:
Normalize number from specific range to 0-1
Example
Math.norm(10, 0, 100);
//0.1
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
max |
number
|
|
Returns:
-
Type
-
number
(static) nPr(num1, num2) → {number}
- Source:
Example
Math.nPr(8, 5);
//6720
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) of(num1, num2) → {number}
- Source:
Find n of `num2 ** n === num1`
Example
Math.of(32, 2);
//5
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) one(num) → {number}
- Source:
Return 1 if even, return -1 if odd
Example
Math.one(2);
//1
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) order(num) → {number}
- Source:
Count total digits of integer part of a number
Example
Math.order(1234);
//3
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) pair(num1, num2) → {number}
- Source:
Example
Math.pair(9, 6);
//100
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
Returns:
-
Type
-
number
(static) pdf(mean, variance, std, num) → {number}
- Source:
Example
Math.pdf(0, 1, 1, 1);
//0.24197072451914337
Parameters:
Returns:
-
Type
-
number
(static) pow(base, exponent) → {number}
- Source:
Calculate power
Example
Math.pow(5, 6);
//15625
Parameters:
Name |
Type |
Description |
base |
number
|
|
exponent |
number
|
|
Returns:
-
Type
-
number
(static) ppf(mean, std, num) → {number}
- Source:
Example
Math.ppf(0, 1, 1);
//3.5005420375954306
Parameters:
Returns:
-
Type
-
number
(static) precision(num) → {number}
- Source:
Count total digits of fractional part of a number
Example
Math.precision(123.678);
//3
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) ramp(num) → {number}
- Source:
Example
Math.ramp(-1);
//0
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) random(minopt, maxopt, roundopt, seedopt, largeropt, equalopt) → {number}
- Source:
Pseudo random number generator uniformly distributed with options
Example
Math.random(0, 1);
//Any number within 0, 1, not rounded
Parameters:
Name |
Type |
Attributes |
Default |
Description |
min |
number
|
<optional>
|
0
|
Minimum |
max |
number
|
<optional>
|
1
|
Maximum |
round |
boolean
|
<optional>
|
|
`true` if generate integer |
seed |
number
|
Array.<number>
|
function
|
<optional>
|
|
Put seed (or function) to generate number here (if array then maximum length is 5), every number must be int32 |
larger |
number
|
<optional>
|
|
return this number if `min > max` |
equal |
number
|
<optional>
|
|
return this number if `min == max` |
Returns:
-
Type
-
number
(static) randomCirc(min1, max1, min2, max2, seedopt) → {number}
- Source:
Returns a Circular distributed random number.
Example
Math.randomCirc(-1, 1, 0, 1);
//Any number within 0, 1, not rounded
Parameters:
Name |
Type |
Attributes |
Description |
min1 |
number
|
|
Minimum generate range, `-1 <= min <= 1` |
max1 |
number
|
|
Maximum generate range, `-1 <= max <= 1` |
min2 |
number
|
|
Minimum result range |
max2 |
number
|
|
Maximum result range |
seed |
number
|
Array.<number>
|
<optional>
|
same as `Math.random` |
Returns:
-
Type
-
number
(static) randomTri(min, max, offsetopt, seedopt) → {number}
- Source:
Example
Math.randomTri(0, 1);
//Any number within 0, 1, not rounded
Parameters:
Name |
Type |
Attributes |
Default |
Description |
min |
number
|
|
|
Minimum |
max |
number
|
|
|
Maximum |
offset |
number
|
<optional>
|
0
|
Offset |
seed |
number
|
Array.<number>
|
<optional>
|
|
same as `Math.random` |
Returns:
-
Type
-
number
(static) range(num, min, max, equalMinopt, equalMaxopt, accuracyopt) → {boolean}
- Source:
Check if number is within range
Example
Math.range(1, 0, 2);
//true
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
min |
number
|
|
|
|
max |
number
|
|
|
|
equalMin |
boolean
|
<optional>
|
|
Change to true if you want to compare `min == num` |
equalMax |
boolean
|
<optional>
|
|
Change to true if you want to compare `num == max` |
accuracy |
number
|
<optional>
|
1
|
Accuracy, or epsilon |
Returns:
-
Type
-
boolean
(static) rational(num, iterationopt, returnDataopt) → {Array.<number>}
- Source:
Calculate numerator and denominator of a number
Example
Math.rational(Math.PI);
//[245850922, 78256779]
245850922 / 78256779 == Math.PI;
//true
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
The number to calculate |
iteration |
number
|
<optional>
|
0
|
Denominator must not larger than this number |
returnData |
array
|
<optional>
|
|
Array to put data |
Returns:
[numerator, denominator]
-
Type
-
Array.<number>
(static) rect(num) → {number}
- Source:
Example
Math.rect(0.5);
//0.5
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) rem(num, min, maxopt, offsetopt) → {number}
- Source:
Calculate remainder with range
Example
Math.rem(-21, 4);
//3
Math.rem(-21, 4, -1);
//-1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
min |
number
|
|
|
|
max |
number
|
<optional>
|
|
|
offset |
offset
|
<optional>
|
0
|
offset |
Returns:
-
Type
-
number
(static) reverse(num, min, max) → {number}
- Source:
Reverse
Example
Math.reverse(4, 5, 10);
//11
Parameters:
Name |
Type |
Description |
num |
number
|
|
min |
number
|
|
max |
number
|
|
Returns:
-
Type
-
number
(static) round2(num, leftopt, rightopt) → {number}
- Source:
Round number around .5
Example
Math.round2(2.5);
//3.1
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
left |
boolean
|
<optional>
|
false
|
Negative, true if away from 0 |
right |
boolean
|
<optional>
|
true
|
Positive, true if away from 0 |
Returns:
-
Type
-
number
(static) shear(num) → {number}
- Source:
Strip off integer part of a number
Example
Math.shear(123.678);
//0.6779999999999973
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) sigmoid(num, sharp) → {number}
- Source:
Example
Math.sigmoid(9, 0.75);
//0.9988304897349445
Parameters:
Name |
Type |
Description |
num |
number
|
|
sharp |
number
|
|
Returns:
-
Type
-
number
(static) smooth(num1, num2, smoothness, isOver) → {number}
- Source:
Example
Math.smooth(0, 1);
//0
Parameters:
Name |
Type |
Description |
num1 |
number
|
|
num2 |
number
|
|
smoothness |
number
|
if isOver is `true`, default is `32`, else `0.1` |
isOver |
boolean
|
use better algorithm but slower |
Returns:
-
Type
-
number
(static) snap(function, num, gap, offsetopt, isLocateopt, digitsopt, baseopt) → {number}
- Source:
Snap a number to nearest number grid
Example
Math.snap(Math.round, 12, 5);
//10
Parameters:
Name |
Type |
Attributes |
Default |
Description |
function |
function
|
|
|
function that adjust number (Ex: Math.round) |
num |
number
|
|
|
|
gap |
number
|
|
|
The interval gap of the grid |
offset |
number
|
<optional>
|
0
|
|
isLocate |
boolean
|
<optional>
|
false
|
use adjust by digit location and base if true |
digits |
number
|
<optional>
|
0
|
|
base |
number
|
<optional>
|
10
|
|
Returns:
-
Type
-
number
(static) snoise(data, returnDataopt) → {Array.<number>}
- Source:
Permutation table for use with Math.snoise
Example
let arraySeed = [];
for (let i = 0; i < 255; i ++) {
arraySeed.push(Math.random(0, 1));
}
Math.tnoise(arraySeed);
//Array of number from 0 to 11
Parameters:
Name |
Type |
Attributes |
Description |
data |
Array.<number>
|
|
array of numbers, must have length = 255, every number must be between 0 <= x < 1,... |
returnData |
array
|
<optional>
|
Array to put data |
Returns:
Array retuned length will always be 512
-
Type
-
Array.<number>
(static) snoise(seed, x, y, zopt) → {number}
- Source:
Simplex noise
Example
let arraySeed = [];
for (let i = 0; i < 512; i ++) {
arraySeed.push(11);
}
Math.snoise(arraySeed, 100, 100);
//-0.4099981169018467
Parameters:
Name |
Type |
Attributes |
Description |
seed |
Array.<number>
|
|
array of numbers, must have length = 512, every number must be between 0 <= x <= 11,... |
x |
number
|
|
|
y |
number
|
|
|
z |
number
|
<optional>
|
if number, turn to 3D simplex noise, else 2D simplex |
Returns:
-
Type
-
number
(static) solve(min, max, func, toleranceopt, iterationopt, epsilonopt) → {number}
- Source:
Solve a function where `f(x) = 0`
Example
Math.solve(-100, 100, (x) => {return 3 * x + 2});
//-0.666666666666666
Parameters:
Name |
Type |
Attributes |
Default |
Description |
min |
number
|
|
|
Minimum guessing range |
max |
number
|
|
|
Maximum guessing range |
func |
function
|
|
|
Function to calculate |
tolerance |
number
|
<optional>
|
0
|
accuracy |
iteration |
number
|
<optional>
|
1000
|
|
epsilon |
number
|
<optional>
|
1e-15
|
|
Returns:
-
Type
-
number
(static) tri(num) → {number}
- Source:
Example
Math.tri(-0.5);
//0.5
Parameters:
Name |
Type |
Description |
num |
number
|
|
Returns:
-
Type
-
number
(static) unpair(num, returnDataopt) → {Array.<number>}
- Source:
Example
Math.unpair(100);
//[9, 6]
Parameters:
Name |
Type |
Attributes |
Description |
num |
number
|
|
|
returnData |
array
|
<optional>
|
Array to put data |
Returns:
[num1, num2]
-
Type
-
Array.<number>
(static) vnoise(seed, x, y, z) → {number}
- Source:
Value noise
Example
Math.vnoise(100, 0, 0, 0);
//0.42069244404355643
Parameters:
Name |
Type |
Description |
seed |
number
|
|
x |
number
|
|
y |
number
|
|
z |
number
|
|
Returns:
-
Type
-
number
(static) worley(seed, x, y, z, func, returnDataopt) → {Array.<number>}
- Source:
Example
Math.worley(0, 0, 0, 0, function(x, y, z) {
return x * x + y * y + z * z;
});
//[0.13724519420856224, 0.1932418811235958, 0.39197915538126826]
Parameters:
Name |
Type |
Attributes |
Description |
seed |
number
|
Array.<number>
|
|
number or array of number, if array then maximum length is 3, every number must be int32 |
x |
number
|
|
|
y |
number
|
|
|
z |
number
|
|
|
func |
function
|
|
function to calculate distance |
returnData |
array
|
<optional>
|
Array to put data |
Returns:
-
Type
-
Array.<number>
(static) wrap(num, min, max, offsetopt) → {number}
- Source:
Wrap number within range
Example
Math.wrap(12, 0, 10);
//2
Parameters:
Name |
Type |
Attributes |
Default |
Description |
num |
number
|
|
|
|
min |
number
|
|
|
|
max |
number
|
|
|
|
offset |
boolean
|
<optional>
|
false
|
|
Returns:
-
Type
-
number