Skip to content

Math.js: Constants & Variables

Built-in Constants

Commonly used mathematical and logical constants are available:

Constant Description Example
pi, PI π ≈ 3.14159 sin(pi/2)
e, E Euler's number ≈ 2.71828 log(e)
i Imaginary unit, sqrt(-1) (2+3i)^2
Infinity Infinity 1/0
NaN Not a Number 0/0
true Boolean true true or false
false Boolean false not true
null Null value null
LN2 Returns the natural logarithm of 2. 0.6931471805599453
LN10 Returns the natural logarithm of 10. 2.302585092994046
LOG2E Returns the base-2 logarithm of E. 1.4426950408889634
LOG10E Returns the base-10 logarithm of E. 0.4342944819032518
phi The golden ratio defined as (1 + sqrt(5)) / 2 1.618033988749895
SQRT1_2 Returns the square root of 1/2. 0.7071067811865476
SQRT2 Returns the square root of 2. 1.4142135623730951
tau Ratio constant of a circle's circumference to radius 2 * pi. 6.283185307179586

Variables

You can store and reuse values using variables.

  • Assignment: variableName = expression
    • Example: x = 5
    • Example: y = x * 2 + 7
  • Assignments do not produce a result line in the output and do not update the @ (last answer) variable.
  • Variables are case-sensitive.
  • Variables and their values are saved and persist between calculator sessions.