General Math Functions and Operators |
Top Previous Next |
Since expressions and script are all Javascript, you can use any of the standard operators and Math functions available when working with scalars (i.e. the most recent value of a tag). Most are pretty standard, like +, -, *, /, >, < etc. A few non-standard ones: == for comparison, not =, which is assignment Math.pow() for power, not ^ used in some other languages Most math functions, like sin and cos, are part of the Javascript Math object, so its Math.sin() not just sin(). The custom math object: Often you'll want to work with arrays of data since historical data is stored in arrays. Javascript doesn't offer math functions that work on arrays, so we've provided them for you along with some extra useful functions. These are all contained in the math object (note lowercase). You can use math. wherever you'd use the standard Math. and the functions will work on arrays, so math.sin() instead of Math.sin. In fact if you just get used to using "math" instead of "Math" it will work on both scalars and arrays. We've also added functions for the standard operators: plus() Extra handy functions: random(x): returns a random number, or if x is specified, an array of random numbers with length = x min(x, y) / max(x, y): if you pass two arguments, it works the same as Math.max(). If you only pass x, it assumes x is an array and gives you the min or max of that array. sum(x): returns the sum of all the elements in x mean(x): returns the mean of all elements in x delta(x): takes an array, and returns an array that contains the difference between each subsequent array element. This is most useful when your tag is a counter, such as the output on many energy meters, and you want the difference between consecutive counts.
|