Log in / create account | Login with OpenID
DocForge
An Open Wiki For Software Developers

Numerical tower

From DocForge

A numerical tower is the sequence of numeric data types spanning integers, rational numbers, and often complex numbers In a programming language.

In object oriented programming languages, a common way to implement data types is by defining a basic set of disjoint types (for example, strings, booleans, byte arrays, and numbers), all considered "objects" (perhaps deriving from a common fundamental "object" class). Then, each numeric type extends the previous, starting with an integer class, then implementing a rational class (this includes decimals) -- defined either as an integer divided by an integer, or as a floating-point number -- and finishing with complex numbers, containing a real and an imaginary component. Various degrees of precision are usually included as well.

Note the futility of implementing a real (irrational) number type: assuming finite computing resources, a number that's stored in a finite number of bits is by definition rational.

Languages that operate closer to the metal are more likely to abandon the mathematical model for a numerical tower in favor of something resembling the underlying processor architecture: integers stored in twos-complement form, and rationals stored as floating-point numbers, either of which can be represented in several ranges of precision depending on the number of bytes dedicated to the number (for example, C's float and double types).