JavaScript Mathematical Functions
Jump to navigation
Jump to search
The following are commonly useful mathematical functions in JavaScript. There are many others, such as Math.exp(a), Math.log(a) and Math.sin(a).
Math.abs | Computes the absolute values. For example, if v1 takes the values of -3, -1, 2 and 4 then Math.abs(v1) takes the values of 3, 1, 2 and 4. |
Math.floor | Rounds down to the nearest whole number. For example, if v1 takes the values of 1.9, 3.1 and -4.7, then Math.abs(v1) takes the values of 1, 3 and -5. |
Math.max | Finds the maximum value. For example, Math.max(v1, v2, v3) will return for each observation the highest value from amongst the three variables for that observation. |
Math.min | Finds the minimum value. For example, Math.min(v1, v2, v3) will return for each observation the lowest value from amongst the three variables for that observation. |
Math.pow | Computes a power. For example, Math.pow (v1,2) computes the square of v1 while Math.pow(v1,0.5) computes the square root. |
Refer to w3schools for more functions.