# compareNatural() Function & Examples

Use the compareNatural() relational function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## compareNatural

#### compareNatural(x, y)

Try it yourself:

```calculio
compareNatural(2, 3)
compareNatural(3, 2)
compareNatural(2, 2)
compareNatural(5cm, 40mm)
compareNatural("2", "10")
compareNatural(2 + 3i, 2 + 4i)
compareNatural([1, 2, 4], [1, 2, 3])
compareNatural([1, 5], [1, 2, 3])
compareNatural([1, 2], [1, 2])
compareNatural({a: 2}, {a: 4})
```

[equal](https://calcul.io/function/equal/index.md)

[unequal](https://calcul.io/function/unequal/index.md)

[smaller](https://calcul.io/function/smaller/index.md)

[compare](https://calcul.io/function/compare/index.md)

---

## compareNatural(): compare text the way people expect

**compareNatural(x, y)** compares strings using natural ordering. Rather than comparing every character literally, it recognizes number runs, so “chapter 2” sorts before “chapter 10”.

## Where it helps

Natural comparison is ideal for filenames, version-like labels, invoice identifiers, and numbered headings. A plain lexical order would place 10 before 2 because “1” precedes “2”; natural order treats the embedded digits as numbers.

## Related comparisons

Use [compareText()](https://calcul.io/function/compareText/index.md) when text collation is the primary concern, and [compare()](https://calcul.io/function/compare/index.md) for general values. Feed a comparator into sorting workflows with [sort()](https://calcul.io/function/sort/index.md). For exact identity rather than ordering, use [equalText](https://calcul.io/function/equalText/index.md) or [equal](https://calcul.io/function/equal/index.md).

## Practical cautions

Natural ordering is a presentation rule, not a numeric parser. Leading zeros, punctuation, case, and locale can still matter. Normalize labels first when a reproducible cross-system order is required.

[All functions](https://calcul.io/functions/index.md)
