A real data type is a
data type
In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or interpreter how the programmer intends to use the data. Most progra ...
used in a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. Computer programs are one component of software, which also includes software documentation, documentation and oth ...
to represent an approximation of a
real number
In mathematics, a real number is a number that can be used to measure a ''continuous'' one-dimensional quantity such as a distance, duration or temperature. Here, ''continuous'' means that values can have arbitrarily small variations. Every ...
.
Because the real numbers are not
countable
In mathematics, a set is countable if either it is finite or it can be made in one to one correspondence with the set of natural numbers. Equivalently, a set is ''countable'' if there exists an injective function from it into the natural numbers ...
, computers cannot represent them exactly using a finite amount of information.
Most often, a computer will use a
rational
Rationality is the quality of being guided by or based on reasons. In this regard, a person acts rationally if they have a good reason for what they do or a belief is rational if it is based on strong evidence. This quality can apply to an abi ...
approximation to a real number.
Rational numbers
The most general data type for a
rational number
In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (e.g. ). The set of all ra ...
stores the numerator and denominator as
integers
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
.
Fixed-point numbers
A fixed-point data type uses the same denominator for all numbers. The denominator is usually a
power of two
A power of two is a number of the form where is an integer, that is, the result of exponentiation with number two as the base and integer as the exponent.
In a context where only integers are considered, is restricted to non-negat ...
. For example, in a fixed-point system that uses the denominator 65,536 (2
16), the hexadecimal number 0x12345678 means 0x12345678/65536 or 305419896/65536 or 4660 + 22136/65536 or about 4660.33777.
Floating-point numbers
A floating-point data type is a compromise between the flexibility of a general rational number data type and the speed of fixed-point arithmetic. It uses some of the bits in the data type to specify a power of two for the denominator. See
IEEE Standard for Floating-Point Arithmetic.
Decimal numbers
Similar to fixed-point or floating-point data type, but with a denominator that is a
power of 10
A power of 10 is any of the integer powers of the number ten; in other words, ten multiplied by itself a certain number of times (when the power is a positive integer). By definition, the number one is a power (the zeroth power) of ten. The fi ...
instead of a power of 2.
{{DEFAULTSORT:Real Data Type
Data types