Home

# Library goog.math

Function Summary
| `angle(number x1, number y1, number x2, number y2) ⇒ 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.
| `angleDifference(number startAngle, number endAngle) ⇒ number` Computes the difference between startAngle and endAngle (angles in degrees).
| `angleDx(number degrees, number radius) ⇒ number` For a given angle and radius, finds the X portion of the offset.
| `angleDy(number degrees, number radius) ⇒ number` For a given angle and radius, finds the Y portion of the offset.
| `average((number|undefined) var_args) ⇒ number` Returns the arithmetic mean of the arguments.
| `clamp(number value, number min, number max) ⇒ number` Takes a number and clamps it to within the provided bounds.
| `isFiniteNumber(number num) ⇒ boolean` Returns whether the supplied number is finite and not NaN.
| `isInt(number num) ⇒ boolean` Returns whether the supplied number represents an integer, i.e. that is has no fractional component. No range-checking is performed on the number.
| `lerp(number a, number b, number x) ⇒ 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).
| `longestCommonSubsequence(?Array.<(Object|null)> array1, ?Array.<(Object|null)> array2, ?Function= opt_compareFn, ?Function= opt_collectorFn) ⇒ ?Array.<(Object|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.

`modulo(number a, number b) ⇒ 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.

| `nearlyEquals(number a, number b, number= opt_tolerance) ⇒ boolean` Tests whether the two values are equal to each other, within a certain tolerance to adjust for floating pount errors.
| `randomInt(number a) ⇒ number` Returns a random integer greater than or equal to 0 and less than {@code a}.
| `sign(number x) ⇒ number` Returns the sign of a number as per the "sign" or "signum" function.
| `standardAngle(number angle) ⇒ number` Standardizes an angle to be in range [0-360). Negative angles become positive, and values greater than 360 are returned modulo 360.
| `standardDeviation((number|undefined) var_args) ⇒ 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
| `sum((number|undefined) var_args) ⇒ number` Returns the sum of the arguments.
| `toDegrees(number angleRadians) ⇒ number` Converts radians to degrees.
| `toRadians(number angleDegrees) ⇒ number` Converts degrees to radians.
| `uniformRandom(number a, number b) ⇒ number` Returns a random number greater than or equal to {@code a} and less than {@code b}.