Carnegie Mellon University
Virtual Sensor Design Tool

Math Constants

ConstantsDescription
Math.EReturns Euler's number (approx. 2.718)
Math.LN2Returns the natural logarithm of 2 (approx. 0.693)
Math.LN10Returns the natural logarithm of 10 (approx. 2.302)
Math.LOG2EReturns the base-2 logarithm of E (approx. 1.442)
Math.LOG10EReturns the base-10 logarithm of E (approx. 0.434)
Math.PIReturns PI (approx. 3.14)
Math.SQRT1_2Returns the square root of 1/2 (approx. 0.707)
Math.SQRT2Returns the square root of 2 (approx. 1.414)

Math Functions

MethodsDescription
Math.abs(x)Returns the absolute value of x
Math.acos(x)Returns the arccosine of x, in radians
Math.asin(x)Returns the arcsine of x, in radians
Math.atan(x)Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
Math.atan2(y,x)Returns the arctangent of the quotient of its arguments
Math.ceil(x)Returns x, rounded upwards to the nearest integer
Math.cos(x)Returns the cosine of x (x is in radians)
Math.exp(x)Returns the value of Ex
Math.floor(x)Returns x, rounded downwards to the nearest integer
Math.log(x)Returns the natural logarithm (base E) of x
Math.max(x,y,z,...,n)Returns the number with the highest value
Math.min(x,y,z,...,n)Returns the number with the lowest value
Math.pow(x,y)Returns the value of x to the power of y
Math.random()Returns a random number between 0 and 1
Math.round(x)Rounds x to the nearest integer
Math.sin(x)Returns the sine of x (x is in radians)
Math.sqrt(x)Returns the square root of x
Math.tan(x)Returns the tangent of an angle
ps.math.even(n)Returns true if n is an even number
ps.math.odd(n)Returns true if n is an odd number
ps.math.fact(n)Returns the product of all of the arguments
ps.math.product(n, n, n...)Returns the tangent of an angle
ps.math.randomBetween(floor, ceiling, digits) Generates a random number between two numbers, defaulting to integers (digits = 0)
ps.math.randomNormal(mean, stdDev) Generates normally distributed random numbers for the given mean and stardard deviation. Defaults to mean = 0, stdDev = 1

Statistics Functions

MethodsDescription
Array.sample(samples) Returns a Array with samples number of random samples from the source Array. It can be used before other Array methods (e.g. myHugeArray.sample(20000).stdDev()) to significantly improve performance while sacrificing some accuracy.
Array.sum()Sums all values in a Array
Array.mean()Returns the arithmetic mean of the source Array
Array.median()Returns the median value of the Array
Array.percentile()Returns the value at the given percentile for the Array
Array.variance()Returns the Variance of the source Array
Array.stdDev()Returns the Standard Deviation of the source Array
Array.max()Returns the highest numeric value of a Array
Array.min()Returns the lowest numeric value of a Array
Array.sortNumber(invert)Returns the Array sorted ascendingly, or decendingly if invert = true
Array.histogram() Returns an object where the key equals the item and the value equals the count of the times that item occured in the Array
Array.countByType()Returns an object that shows the total count of each type in a Array
ps.stats.normsinv(p) returns the inverse of the standard normal cumulative distribution for a given p percentile