AQA 7517, section 4.5.1.2
An integer is a whole number that can be positive, negative or zero. The set of integers is written :
Relationship to the natural numbers
Every natural number is also an integer, so the natural numbers are a subset of the integers:
The integers add the negative whole numbers. This means subtraction always works: the answer to is , which is an integer.
Key properties
- No fractional parts: 4 and −7 are integers, but 2.5 is not.
- The set is infinite in both directions (and is countable).
- Adding, subtracting and multiplying two integers always gives an integer. Dividing might not: .
Where they are used in computing
- Quantities that can go below zero: a bank balance in pence, a temperature in whole degrees, a score difference.
- The integer data type in programming languages.
- Signed binary (two's complement) represents integers in a computer (see 4.5.4.3).
balance = 20
balance = balance - 50
print(balance) # -30: still an integer
print(type(balance)) # <class 'int'>
Worked example
Task: which of these are integers: , , , , ?
- : yes.
- : yes.
- : yes in value (it equals 3), although in a program a number written
3.0is stored as a float and not an integer. - : no, because it is a fraction.
- : yes.
Exam tip: an integer is a whole number, including negative numbers and zero. Don't confuse the mathematical set with a programming data type, which can only store a limited range of integers.
Check yourself
What is the difference between the natural numbers and the integers?
The integers also include the negative whole numbers. The natural numbers are a subset of the integers.
Is −7 an integer? Is 7.5?
−7 is an integer. 7.5 is not, because it has a fractional part.
Why are integers needed to represent a bank overdraft?
An overdraft is a negative balance, which the natural numbers can't represent.