Math.js: Built-in Functions
JS Calc via Math.js provides a vast range of functions. Angles for trigonometric functions are in radians by default (you can use the deg unit for degrees, e.g., sin(45 deg)).
Trigonometric
sin(x),cos(x),tan(x)asin(x),acos(x),atan(x),atan2(y, x)sinh(x),cosh(x),tanh(x)asinh(x),acosh(x),atanh(x)- Example:
sin(pi/4),cos(30 deg) -
Angles are expected in radians by default. You can directly use degree units:
sin(30 deg) = 0.5cos(pi/4 rad) = 0.7071067811865476 // rad is often implicit for plain numbers -
For more comprehensive information on unit handling, see the Units and Conversions page.
Exponential & Logarithmic
exp(x)(e^x)log(x)(natural logarithm)log10(x)(base-10 logarithm)log2(x)(base-2 logarithm)- Example:
log(e^3),log10(100)
Powers & Roots
pow(base, exp)(same asbase^exp)sqrt(x)cbrt(x)nthRoot(a [, root])(root defaults to 2)- Example:
sqrt(16),nthRoot(27, 3)
Rounding:
round(x [, n])(round to n decimals)ceil(x [, n])floor(x [, n])fix(x [, n])(round towards zero)- Example:
round(pi, 2),floor(3.8)
Statistical (often on arrays/matrices):
mean(A),median(A),std(A),variance(A)min(A),max(A),sum(A),prod(A)quantileSeq(A, probOrN)- Example:
mean([1,2,3,7]),max(1, 5, 2)
Probability:
factorial(n)(orn!)permutations(n [, k])combinations(n, k)gamma(n)- Example:
5!,combinations(5,2)
Other:
abs(x), sign(x), isNumeric(x), isInteger(x), isPrime(x) (for numbers), gcd(a,b), lcm(a,b) (for numbers).
For a complete list, refer to the official Math.js Functions Documentation.