goog.math
Functions
angle( x1, y1, x2, y2 ) → number
number
Computes the angle between two points (x1,y1) and (x2,y2). Angle zero points in the +X direction, 90 degrees points in the +Y direction (down) and from there we grow clockwise towards 360 degrees.
Parameters |
| ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
angleDifference( startAngle, endAngle ) → number
number
Computes the difference between startAngle and endAngle (angles in degrees).
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
angleDx( degrees, radius ) → number
number
angleDy( degrees, radius ) → number
number
average( ...var_args ) → number
number
clamp( value, min, max ) → number
number
isFiniteNumber( num ) → boolean
boolean
isInt( num ) → boolean
boolean
isNegativeZero( num ) → boolean
boolean
lerp( a, b, x ) → number
number
Performs linear interpolation between values a and b. Returns the value between a and b proportional to x (when x is between 0 and 1. When x is outside this range, the return value is a linear extrapolation).
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
log10Floor( num ) → number
number
Returns the precise value of floor(log10(num)). Simpler implementations didn't work because of floating point rounding errors. For example
- Math.floor(Math.log(num) / Math.LN10) is off by one for num == 1e+3.
- Math.floor(Math.log(num) * Math.LOG10E) is off by one for num == 1e+15.
- Math.floor(Math.log10(num)) is off by one for num == 1e+15 - 1.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
longestCommonSubsequence<S, T>( array1, array2, opt_compareFn, opt_collectorFn ) → Array<(S|null)>
Array<(S|null)>
JavaScript implementation of Longest Common Subsequence problem. http://en.wikipedia.org/wiki/Longest_common_subsequence
Returns the longest possible array that is subarray of both of given arrays.
Parameters |
| ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
modulo( a, b ) → number
number
The % operator in JavaScript returns the remainder of a / b, but differs from some other languages in that the result will have the same sign as the dividend. For example, -1 % 8 == -1, whereas in some other languages (such as Python) the result would be 7. This function emulates the more correct modulo behavior, which is useful for certain applications such as calculating an offset index in a circular list.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
nearlyEquals( a, b, opt_tolerance ) → boolean
boolean
Tests whether the two values are equal to each other, within a certain tolerance to adjust for floating point errors.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
randomInt( a ) → number
number
safeCeil( num, opt_epsilon ) → number
number
safeFloor( num, opt_epsilon ) → number
number
A tweaked variant of Math.floor
which tolerates if the passed number
is infinitesimally smaller than the closest integer. It often happens with
the results of floating point calculations because of the finite precision
of the intermediate results. For example Math.floor(Math.log(1000) /
Math.LN10) == 2
, not 3 as one would expect.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
sampleVariance( ...var_args ) → number
number
Returns the unbiased sample variance of the arguments. For a definition, see e.g. http://en.wikipedia.org/wiki/Variance
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
sign( x ) → number
number
standardAngle( angle ) → number
number
standardAngleInRadians( angle ) → number
number
standardDeviation( ...var_args ) → number
number
Returns the sample standard deviation of the arguments. For a definition of sample standard deviation, see e.g. http://en.wikipedia.org/wiki/Standard_deviation
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
sum( ...var_args ) → number
number
toDegrees( angleRadians ) → number
number
toRadians( angleDegrees ) → number
number
uniformRandom( a, b ) → number
number
Properties
interpolator → {Interpolator1: function(this: goog.math.interpolator.Interpolator1): ?, Linear1: function(new: goog.math.interpolator.Linear1), Pchip1: function(new: goog.math.interpolator.Pchip1), Spline1: function(new: goog.math.interpolator.Spline1)}
{Interpolator1: function(this: goog.math.interpolator.Interpolator1): ?, Linear1: function(new: goog.math.interpolator.Linear1), Pchip1: function(new: goog.math.interpolator.Pchip1), Spline1: function(new: goog.math.interpolator.Spline1)}
No information.