jsguides

Math.SQRT1_2

Math.SQRT1_2 is a static property of the Math object that represents the square root of 1/2, approximately 0.7071067811865476. It is a read-only constant; you cannot change its value.

Mathematically, this equals 1 / Math.sqrt(2) or Math.sqrt(2) / 2. It appears frequently in trigonometry (cos 45° = sin 45°), normalization calculations, and probability distributions.

Syntax

Math.SQRT1_2

Value

Math.SQRT1_2; // 0.7071067811865476

Examples

Basic usage

console.log(Math.SQRT1_2);
// 0.7071067811865476

Verifying the value

You can confirm that the constant matches the algebraic definition by checking both common equivalent forms. The first comparison divides 1 by √2, and the second multiplies √2 by 1/2. Both return true, confirming the engine’s constant is consistent with Math.sqrt.

console.log(Math.SQRT1_2 === 1 / Math.sqrt(2));
// true

console.log(Math.SQRT1_2 === Math.sqrt(2) / 2);
// true

Trigonometric calculations

The value 1/√2 appears in angle calculations because cos(45°) and sin(45°) both equal it. The snippet below uses Math.PI / 4 which is 45° in radians. If you have ever worked with rotation matrices or unit-circle diagrams, this value recurs every time a pair of perpendicular components shares equal weight.

// cos(45°) = sin(45°) = 1/√2 = √2/2
console.log(Math.cos(Math.PI / 4));
// 0.7071067811865476

console.log(Math.sin(Math.PI / 4));
// 0.7071067811865476

Normalizing a 2D vector

When normalizing diagonal vectors, you divide by √2. The function below computes the Euclidean magnitude of (x, y), then scales both components to produce a unit-length vector. For the diagonal direction (1, 1), each scaled component lands at exactly 1/√2, which matches Math.SQRT1_2.

function normalize2D(x, y) {
  const magnitude = Math.sqrt(x * x + y * y);
  return {
    x: x / magnitude,
    y: y / magnitude
  };
}

// Unit vector along (1, 1) diagonal
const normalized = normalize2D(1, 1);
console.log(normalized.x);
// 0.7071067811865476

console.log(normalized.x === Math.SQRT1_2);
// true

Calculating diagonal length

For a unit square, the diagonal length is √2, but each component is 1/√2. The function below multiplies the given side length by Math.SQRT1_2 for both x and y, which is exactly what you need when decomposing a diagonal movement into its horizontal and vertical parts.

function diagonalComponents(side) {
  return {
    x: side * Math.SQRT1_2,
    y: side * Math.SQRT1_2
  };
}

console.log(diagonalComponents(10));
// { x: 7.071067811865476, y: 7.071067811865476 }

Probability: normal distribution

The standard normal distribution uses √2 in its probability density function. The formula exp(-0.5 x²) / √(2π) includes a √2 inside the denominator through Math.sqrt(2 * Math.PI). At x = 0 the exponential term is 1, so the result is simply 1 / √(2π).

function normalPDF(x) {
  return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI);
}

console.log(normalPDF(0));
// 0.3989422804014327

Photography: f-stop calculations

Aperture ratios relate to √2 because each full f-stop halves or doubles the light hitting the sensor. The following snippet calculates relative aperture area, which drops by roughly half when the f-number increases by a factor of √2. This is why f/1.4 and f/2.0 are one stop apart.

// Each f-stop doubles light, related to √2
function apertureArea(fNumber) {
  return Math.PI / (fNumber * fNumber);
}

console.log(apertureArea(1.414));
// Approximately 1/2 times the area at f/1

Audio: RMS calculations

Root mean square calculations use √2 for sine waves because the RMS value of a pure tone is amplitude divided by √2. The function below makes that explicit, and the comparison at the end confirms that amplitude / √2 equals Math.SQRT1_2 when amplitude is 1.

function sineWaveRMS(amplitude) {
  return amplitude / Math.sqrt(2);
}

console.log(sineWaveRMS(1));
// 0.7071067811865476

console.log(sineWaveRMS(1) === Math.SQRT1_2);
// true

Where Math.SQRT1_2 shows up

The constant appears whenever a calculation splits evenly across two perpendicular directions. Diagonal movement in games, 45-degree trigonometry, and normalization all land on the same value because each component of the vector is exactly 1 / √2. Using Math.SQRT1_2 makes that relationship obvious without repeating the formula every time.

It is also helpful when you want consistent code paths. If several parts of your app rely on the same scale factor, naming the constant once reduces the chance of a typo or a mismatched approximation in one place. That consistency matters in graphics, audio, and physics calculations where small differences can compound.

When a literal is worse

Hardcoding 0.7071067811865476 works, but it hides the math. A named constant tells the reader that the number is not arbitrary; it is the exact square root of one half. That makes the code easier to audit and easier to port if you later change the surrounding formula.

It also keeps future edits safer. If someone needs to refactor a geometry helper or normalize a vector differently, the named constant gives them a clear anchor. That is worth more than having one less line of code.

Common patterns

Avoiding repeated calculations

// Instead of computing sqrt(1/2) each time
function calculateHalfRoot(value) {
  return value * Math.SQRT1_2;
}

Scale factor for unit circle

The x and y coordinates at 45° on the unit circle both equal 1/√2. Rather than repeating the computation every time you need that value, the function below returns the constant directly. When you need the same scale factor across multiple geometry helpers, this avoids drift from slightly differing approximations.

// Getting the x or y coordinate at 45 degrees
function unitCircle45() {
  return Math.SQRT1_2;
}

Why use Math.SQRT1_2?

Using Math.SQRT1_2 instead of hardcoding 0.7071067811865476 provides several advantages:

  1. Precision — The constant is defined to full floating-point precision
  2. Readability — Code clearly expresses the mathematical concept
  3. Standardization — Matches mathematical notation in formulas
  4. Performance — The value is pre-computed by the JavaScript engine
  5. Intent — Using Math.SQRT1_2 signals that 1/√2 is intentionally used

See also

  • Math.sqrt() — returns the square root of a number
  • Math.SQRT2 — the square root of 2
  • Math.PI — the ratio of circle circumference to diameter