TExcelTAD
Home › Basic Math & Pre-Algebra › Kinds of Numbers

Kinds of Numbers

Not all numbers are the same kind. Counting numbers, whole numbers, integers, rational numbers, irrational numbers and real numbers are families that fit inside each other like nested boxes. Knowing which family a number belongs to tells you what you can safely do with it, and in code it decides which data type you should use.

The number families

Family Symbol What it contains Examples
Natural (counting) numbers N\mathbb{N} 1, 2, 3, 4, … 1, 7, 365
Whole numbers 0 and the natural numbers 0, 12, 1000
Integers Z\mathbb{Z} whole numbers and their negatives −40, −1, 0, 5
Rational numbers Q\mathbb{Q} anything that can be written as a fraction pq\frac{p}{q} of integers (q≠0q \ne 0) 12\frac{1}{2}, −34-\frac{3}{4}, 0.25, 6
Irrational numbers real numbers that are not a fraction 2\sqrt{2}, π\pi, ee
Real numbers R\mathbb{R} all rational and irrational numbers: every point on the number line everything above

Note: Some books start the natural numbers at 0. Programmers usually do too: arrays are indexed from 0. When it matters, say "positive integers" (1, 2, 3, …) or "non-negative integers" (0, 1, 2, …) to be clear.

Each family contains the one before it:

natural⊂whole⊂integers⊂rationals⊂realsirrationals⊂reals\begin{aligned} \text{natural} \subset \text{whole} \subset \text{integers} \subset {} &\text{rationals} \subset \text{reals} \\ &\text{irrationals} \subset \text{reals} \end{aligned}

The symbol ⊂\subset means "is contained in". So 5 is a natural number, but it is also a whole number, an integer, a rational number (51\frac{5}{1}) and a real number. A number is either rational or irrational, never both.

Why we needed each new family

Each family was invented because the previous one could not answer some question:

  • Subtraction needs negatives: 3−53 - 5 has no answer among the whole numbers, so we add the integers (−2).
  • Division needs fractions: 7÷27 \div 2 has no integer answer, so we add the rationals (72=3.5\frac{7}{2} = 3.5).
  • Square roots need irrationals: no fraction squared gives exactly 2, so 2≈1.41421…\sqrt{2} \approx 1.41421\ldots must be a new kind of number.

Rational numbers as decimals

Every rational number, written as a decimal, either stops (terminates) or repeats a block of digits forever:

14=0.25(stops)13=0.3333…(the 3 repeats)57=0.714285714285…(the block 714285 repeats)\begin{aligned} \frac{1}{4} &= 0.25 && \text{(stops)} \\ \frac{1}{3} &= 0.3333\ldots && \text{(the 3 repeats)} \\ \frac{5}{7} &= 0.714285714285\ldots && \text{(the block 714285 repeats)} \end{aligned}

An irrational number's decimal never stops and never settles into a repeating block. π=3.14159265358979…\pi = 3.14159265358979\ldots goes on without a pattern. That is why a computer can never store π\pi exactly: it keeps only the first 16 or so digits.

python · try it yourself
from fractions import Fraction
import math

print(Fraction(1, 4), "=", 1 / 4)
print(Fraction(5, 7), "=", 5 / 7)
print("0.75 as a fraction:", Fraction("0.75"))
print("pi (as stored):", math.pi)
print("sqrt(2):", math.sqrt(2))
print("sqrt(2) squared:", math.sqrt(2) ** 2)
1/4 = 0.25
5/7 = 0.7142857142857143
0.75 as a fraction: 3/4
pi (as stored): 3.141592653589793
sqrt(2): 1.4142135623730951
sqrt(2) squared: 2.0000000000000004

The last line is a giveaway: the computer's 2\sqrt{2} is only a rational approximation, so squaring it does not give exactly 2.

Classifying numbers in Python

Python's types line up with the families. Integers are int. Decimal numbers are float, an approximation of a real number. Exact rationals are Fraction. Let's sort a few values:

python · try it yourself
def classify(x):
    kinds = []
    if x == int(x):
        if x >= 1:
            kinds.append("natural")
        if x >= 0:
            kinds.append("whole")
        kinds.append("integer")
    kinds.append("rational")
    kinds.append("real")
    return kinds

for value in [7, 0, -3, 2.5, -0.75]:
    print(f"{value:>6}:", ", ".join(classify(value)))
     7: natural, whole, integer, rational, real
     0: whole, integer, rational, real
    -3: integer, rational, real
   2.5: rational, real
 -0.75: rational, real

The function only works for numbers given as finite decimals, which are always rational. It cannot recognise π\pi as irrational: a float has already chopped π\pi down to a fraction. Deciding irrationality needs mathematics, not just computation.

Even and odd, positive and negative

Two more ways to sort integers come up constantly:

  • Even numbers divide by 2 with no remainder (…, −4, −2, 0, 2, 4, …); odd numbers leave remainder 1 (1, 3, 5, …). In Python: n % 2 == 0 means even.
  • Positive numbers are greater than 0, negative numbers are less than 0, and 0 is neither.

In software

Choosing a number type is choosing a family:

  • Counts and indexes (items in a cart, array positions) are whole numbers: use integers.
  • Temperatures, bank balances, coordinates can be negative: use signed integers or floats.
  • Exact ratios (recipe scaling, music rhythms, probability by hand) suit fractions.
  • Measurements and physics (positions in a game, weights in a neural network) are real numbers, approximated by floats. Every float is secretly a rational number with a power-of-two denominator, which is why Floating Point has surprises.

Exercises

Exercise 1: Sort them

For each number, give the smallest family it belongs to: 12, −8, 0, 35\frac{3}{5}, 9\sqrt{9}, 5\sqrt{5}, 0.121212… (repeating).

Answer

12 natural · −8 integer · 0 whole · 35\frac{3}{5} rational · 9\sqrt{9} natural · 5\sqrt{5} irrational · 0.1212… rational

Solution
text
12        counting number              → natural
−8        negative, but whole          → integer
0         not a counting number        → whole
3/5       fraction of integers         → rational
√9 = 3    a counting number in disguise → natural
√5        5 is not a perfect square    → irrational (2.2360679…)
0.1212…   repeating decimal = 12/99 = 4/33 → rational

Exercise 2: True or false

(a) Every integer is a rational number. (b) Every rational number is an integer. (c) 0 is a natural number in the convention N={1,2,3,…}\mathbb{N} = \{1, 2, 3, \ldots\}.

Answer

(a) true, (b) false, (c) false.

Solution

(a) Any integer nn can be written as n1\frac{n}{1}, so it is rational. (b) 12\frac{1}{2} is rational but not an integer. (c) With N\mathbb{N} starting at 1, 0 is a whole number but not a natural number.

Exercise 3: Repeating decimal to fraction

Use Fraction to find the fraction for 0.375 and check that 433\frac{4}{33} really is 0.121212….

Answer

0.375=380.375 = \frac{3}{8}, and 433=0.121212…\frac{4}{33} = 0.121212\ldots (the block 12 repeats).

Solution

0.375=37510000.375 = \frac{375}{1000}; dividing top and bottom by 125 gives 38\frac{3}{8}.

python · try it yourself
from fractions import Fraction

print(Fraction("0.375"))
print(4 / 33)
3/8
0.12121212121212122

The last digit 2 is the float's rounding; the true decimal repeats 12 forever.

Exercise 4: Even, odd, sign

Write a loop that prints, for each of −4, −1, 0, 3, 10, whether it is even or odd and whether it is positive, negative or zero.

Answer

−4 even negative · −1 odd negative · 0 even zero · 3 odd positive · 10 even positive

Solution
python · try it yourself
for n in [-4, -1, 0, 3, 10]:
    parity = "even" if n % 2 == 0 else "odd"
    if n > 0:
        sign = "positive"
    elif n < 0:
        sign = "negative"
    else:
        sign = "zero"
    print(n, parity, sign)
-4 even negative
-1 odd negative
0 even zero
3 odd positive
10 even positive

Python's % always returns 0 or 1 for n % 2, even for negative nn, so the test works for negatives too.

Test yourself

Which of these numbers is irrational?

  1. 0.5
  2. 16\sqrt{16}
  3. 7\sqrt{7}
  4. −227-\frac{22}{7}

Which family is the smallest one that contains −5?

  1. Natural numbers
  2. Whole numbers
  3. Integers
  4. Irrational numbers

The decimal 0.272727… (27 repeating forever) is…

  1. irrational, because it never ends
  2. rational, because it repeats
  3. not a real number
  4. an integer