Absolute Value — Distance from Zero

By dan • June 2, 2026 • 2 min read

# Absolute Value — Distance from Zero

![Absolute value — equal arrows from zero to +3 and -3, showing identical distance](https://askrobots.com/files/public/7a7b19e8-b7f1-4ebc-b8b6-16e37b181dcb/)

## Plain English first
Absolute value answers one question: **how far from zero?**

It strips away direction and gives you only distance. 3 steps right: distance 3. 3 steps left: distance also 3. Same number, opposite directions — absolute value makes them equal.

## The picture

```text
|← 3 units →| |← 3 units →|
←──────────────────────────────────────→
-3 0 3

|-3| = 3 |3| = 3
```

## Standard math notation

```text
|n| = n if n ≥ 0 (already positive)
|n| = -n if n < 0 (flip the sign)

|7| = 7
|-7| = 7
|-3.5| = 3.5

Distance between a and b: |a - b|
```

## Verbose Python with descriptive names

```python
def compute_absolute_value(number):
"""
Absolute value is the distance from zero — always non-negative.
If positive or zero: keep it. If negative: flip the sign.
"""
if number >= 0:
return number
else:
return -number # -(-3) = 3

def compute_distance_between_points(point_a, point_b):
"""
Subtract to find the gap; absolute value makes it positive.
Distance from 2 to 7 and from 7 to 2 are both 5.
"""
return compute_absolute_value(point_a - point_b)

def check_if_within_tolerance(measured_value, target_value, allowed_error):
"""
Common engineering use: is this measurement close enough?
We care about the SIZE of the error, not its direction.
"""
size_of_error = compute_absolute_value(measured_value - target_value)
passed = size_of_error <= allowed_error
print(f" Error size: {size_of_error:.3f}, allowed: ±{allowed_error} → {'PASS ✓' if passed else 'FAIL ✗'}")
return passed

# Demonstrations
print(compute_absolute_value(-7)) # 7
print(compute_distance_between_points(-3, 4)) # 7
check_if_within_tolerance(98.3, 98.6, 0.5) # PASS
check_if_within_tolerance(10.08, 10.0, 0.05) # FAIL
```

## Where absolute value appears
- **Error measurement** — size of the error, regardless of direction
- **Distance formulas** — always positive, regardless of subtraction order
- **Tolerance checks** — is this within ±X of the target?

## Common mistakes
- **`|-5| = -5` is wrong.** Always non-negative. `|-5| = 5`.
- **`|a + b| ≠ |a| + |b|`** in general. `|3 + (-3)| = 0`, but `|3| + |-3| = 6`.

## See also
- [The Number Line](/articles/257eeafa-b654-40a8-97f5-6be800ad1c8e)
- [Negative Numbers](/articles/45845a19-1e29-4a92-8cdd-7bc20ae05a20)
- [Math Foundations — Visual Table of Contents](/articles/d404884f-54fc-4289-b3f1-baaad2bec6b2)