Math.js is a math language that transpiles to JavaScript. It allows you to write equations with ease and any prior knowledge.
1 + 2 + 3 # 6
We add up 1
, 2
and 3
which would result in 6. #
is the start of a comment, so it's excluded from any equation.
1.5 * 2 # 3
You can easily multiply numbers, as seen here.
(1 + 2)^3 - 5 * 3 # 12
Math.js follows the standard Order of Operations when calculating an equation.
Math.js has several built in functions you can use.
log(x)
natural logarithm of xlogb(x)
logarithm of x with base b, examplelog10(100) # 2
sqrt(x)
take the square root of xsin(x)
take the sin of xcos(x)
take the cos of xtan(x)
take the tan of xfloor(x)
round x downceil(x)
round x upround(x)
round x to the nearest integerabs(x)
take the absolute value of xradians(x)
turn x degrees into radiansdegrees(x)
turn x radians into degrees
Example usage:
round(2 + sqrt(2^2 / (4 - 2))) # 3
x = 10 / 2
10 - x # 5
You can easily create variables. These variables can be used in equations, functions and to assign other variables.