Math for Computer Science

1 | Negative numbers

Practice Table of Contents

Introduction

Anything that can be counted can be represented by a positive number: the number of students in a classroom; the number of books those students have read this year; the number of minutes in a lunch break. Even more abstract ideas can be described by positive numbers: the amount of money in a bank account; the height of a mountain peak; the temperature outside on a summer afternoon.

Where there is something, there can also be nothing: there are times when every classroom is empty; when the year begins, no books have been read; some lunch breaks are spoiled by lunch detention. The concept of zero is common enough, but what about numbers less than zero? If we can count with positive numbers, can we also count with negative numbers?

It turns out that some ideas are most easily described by numbers less than zero: when someone spends more money than they have, they acquire debt, a negative amount of money; when a scuba diver descends into the ocean, they acquire depth, a negative height; on a cold night in a cold place, the temperature drops below zero degrees, a negative temperature.


What are negative numbers?

  • Any number less than zero is a negative number.
  • All of the negative whole numbers, along with zero and all of the positive whole numbers, are known as integers.
  • On a number line, numbers always increase (become "more positive") to the right and decrease (become "more negative") to the left.

How are negative numbers used in computer science?

In computer science, negative numbers are quite common. Negative numbers can be used to describe the position of an object in a video game or to model ideas like money, temperature or elevation in a computer program.

Examples

Points on a number line

Your browser does not support the canvas element.

Q: Where is the blue dot on the number line?

A: Since numbers become "more negative" to the left on a number line, we can count back from zero to find that the blue dot is located at -3.


Distance between points

Your browser does not support the canvas element.

Q: What is the distance between -3 and 5?

A: Since -3 is 3 units from zero and 5 is 5 units from zero, the distance between -3 and 5 is a total of 8 units.

Practice | Negative numbers