chapter  2
20 Pages

Numbers

Numbers are the building blocks of mathematics and, of course, computers are extremely adept with numbers. There are several ways in which numbers are handled in C++. In this chapter, we explore the different representations of numbers and how to convert between representations. We also catalogue the various operations we can perform with numbers. Numbers in C++ are divided into two broad categories: integers and reals. Each

of these categories is refined further. Of course, to a mathematician every integer is a real number, so these categories may seem spurious. The reasons for having many different ways to represent numbers are efficiency and accuracy; if the quantities with which we are computing are known to be integral, then using an integer representation is not subject to roundoff error and the computations are faster.