Namespace goog.math
code »Global Functions
code »goog.math.angle ( x1, y1, x2, y2 ) ⇒ numberComputes 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.
numbercode »goog.math.angleDifference ( startAngle, endAngle ) ⇒ numberComputes the difference between startAngle and endAngle (angles in degrees).
number| Parameters |
|---|
| Returns |
|
code »goog.math.angleDx ( degrees, radius ) ⇒ numberFor a given angle and radius, finds the X portion of the offset.
numbercode »goog.math.angleDy ( degrees, radius ) ⇒ numberFor a given angle and radius, finds the Y portion of the offset.
numbercode »goog.math.average ( var_args ) ⇒ numberReturns the arithmetic mean of the arguments.
number| Parameters |
|---|
|
| Returns |
NaN if no arguments
were provided or any of the arguments is not a valid number). |
code »goog.math.clamp ( value, min, max ) ⇒ numberTakes a number and clamps it to within the provided bounds.
numbercode »goog.math.isFiniteNumber ( num ) ⇒ booleanReturns whether the supplied number is finite and not NaN.
boolean| Parameters |
|---|
|
| Returns |
num is a finite number. |
code »goog.math.isInt ( num ) ⇒ booleanReturns whether the supplied number represents an integer, i.e. that is has
no fractional component. No range-checking is performed on the number.
boolean| Parameters |
|---|
|
| Returns |
num is an integer. |
code »goog.math.lerp ( a, b, x ) ⇒ numberPerforms 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).
numbercode »goog.math.log10Floor ( num ) ⇒ numberReturns 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.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.longestCommonSubsequence ( array1, array2, opt_compareFn, opt_collectorFn ) ⇒ !Array.<Object>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.
!Array.<Object>| Parameters |
|---|
|
| Returns |
|
code »goog.math.modulo ( a, b ) ⇒ numberThe % 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.
numbercode »goog.math.nearlyEquals ( a, b, opt_tolerance ) ⇒ booleanTests whether the two values are equal to each other, within a certain
tolerance to adjust for floating point errors.
booleancode »goog.math.randomInt ( a ) ⇒ numberReturns a random integer greater than or equal to 0 and less than a.
numbera.| Parameters |
|---|
|
| Returns |
|
code »goog.math.safeCeil ( num, opt_epsilon ) ⇒ numberA tweaked variant of Math.ceil. See goog.math.safeFloor for
details.
numberMath.ceil. See goog.math.safeFloor for
details.code »goog.math.safeFloor ( num, opt_epsilon ) ⇒ numberA 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.
numberMath.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.code »goog.math.sampleVariance ( var_args ) ⇒ numberReturns the unbiased sample variance of the arguments. For a definition,
see e.g. http://en.wikipedia.org/wiki/Variance
number| Parameters |
|---|
|
| Returns |
NaN if any of the samples is
not a valid number). |
code »goog.math.sign ( x ) ⇒ numberReturns the sign of a number as per the "sign" or "signum" function.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.standardAngle ( angle ) ⇒ numberNormalizes an angle to be in range [0-360). Angles outside this range will
be normalized to be the equivalent angle with that range.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.standardAngleInRadians ( angle ) ⇒ numberNormalizes an angle to be in range [0-2*PI). Angles outside this range will
be normalized to be the equivalent angle with that range.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.standardDeviation ( var_args ) ⇒ numberReturns the sample standard deviation of the arguments. For a definition of
sample standard deviation, see e.g.
http://en.wikipedia.org/wiki/Standard_deviation
number| Parameters |
|---|
|
| Returns |
NaN if any of the samples is
not a valid number). |
code »goog.math.sum ( var_args ) ⇒ numberReturns the sum of the arguments.
number| Parameters |
|---|
|
| Returns |
NaN if any of the arguments is not a valid number). |
code »goog.math.toDegrees ( angleRadians ) ⇒ numberConverts radians to degrees.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.toRadians ( angleDegrees ) ⇒ numberConverts degrees to radians.
number| Parameters |
|---|
|
| Returns |
|
code »goog.math.uniformRandom ( a, b ) ⇒ numberReturns a random number greater than or equal to a and less than
b.
numbera and less than
b.