Absolute Value Calculator Formula

Understand the math behind the absolute value calculator. Each variable explained with a worked example.

Formulas Used

Abs Val

abs_val = abs(num)

Sign

sign = num > 0 ? 1 : (num < 0 ? -1 : 0)

Squared

squared = pow(num, 2)

Variables

VariableDescriptionDefault
numNumber-7.5

How It Works

Absolute Value

Definition

|x| = x if x ≥ 0, and |x| = -x if x < 0

The absolute value of a number is its distance from zero on the number line, always non-negative.

Properties

  • |x| ≥ 0 for all x
  • |x| = 0 only when x = 0
  • |xy| = |x| × |y|
  • |x + y| ≤ |x| + |y| (triangle inequality)
  • Worked Example

    Find the absolute value of -7.5.

    num = -7.5
    1. 01|-7.5| = 7.5
    2. 02The number is negative, so the sign is -1
    3. 03(-7.5)² = 56.25

    Ready to run the numbers?

    Open Absolute Value Calculator