Hubbry Logo
Real data typeReal data typeMain
Open search
Real data type
Community hub
Real data type
logo
7 pages, 0 posts
0 subscribers
Be the first to start a discussion here.
Be the first to start a discussion here.
Real data type
Real data type
from Wikipedia

A real data type is a data type used in a computer program to represent an approximation of a real number. Because the real numbers are not countable, computers cannot represent them exactly using a finite amount of information. Most often, a computer will use a rational approximation to a real number.

Rational numbers

[edit]

The most general data type for a rational number (a number that can be expressed as a fraction) stores the numerator and the denominator as integers. For example 1/3, which can be calculated to any desired precision. Rational number are used, for example, in Interpress from Xerox Corporation.[1]

Fixed-point numbers

[edit]

A fixed-point data type uses the same, implied, denominator for all numbers. The denominator is usually a power of two. For example, in a hypothetical fixed-point system that uses the denominator 65,536 (216), the hexadecimal number 0x12345678 (0x1234.5678 with sixteen fractional bits to the right of the assumed radix point) means 0x12345678/65536 or 305419896/65536, 4660 + the fractional value 22136/65536, or about 4660.33777. An integer is a fixed-point number with a fractional part of zero.

Floating-point numbers

[edit]

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 an exponent for the denominator, today usually power of two although both ten and sixteen have been used.[2]

Decimal numbers

[edit]

The decimal type is similar to fixed-point or floating-point data type, but with a denominator that is a power of 10 instead of a power of 2.

See also

[edit]

References

[edit]
Revisions and contributorsEdit on WikipediaRead on Wikipedia
from Grokipedia
In , the real data type is a numeric designed to represent real numbers—values that include both and fractional components—using to approximate the infinite precision of mathematical real numbers with finite binary storage. This type is essential for computations involving non-integer values, such as scientific calculations, , and , where exact integer representation is insufficient. The most widely adopted standard for real data types is , which specifies binary floating-point formats for consistent representation and arithmetic operations across hardware and software platforms. Common implementations include single-precision (typically 32 bits, offering about 6-7 decimal digits of precision) and double-precision (64 bits, providing 15-16 decimal digits), with the former often denoted as REAL*4 in or float in C, and the latter as REAL*8 or double. In languages like and Pascal, the REAL keyword directly declares variables of this type, while others like Python use float as the equivalent. Key characteristics of real data types include support for special values like positive and negative , (Not a Number) for invalid operations, and gradual underflow to handle very small numbers without abrupt loss of precision. However, due to binary representation limitations, real types cannot precisely store all fractions (e.g., 0.1 may be approximated), leading to potential rounding errors in extended computations. These types are implemented in nearly all modern programming languages and hardware to ensure portability and reliability in numerical applications.

Overview

Definition and Purpose

A in is a fundamental data type designed to store and manipulate non-integer real numbers, which include fractional and irrational values, using finite precision representations. Unlike exact mathematical real numbers, which form an infinite continuum, computational real types approximate these values within the constraints of available and capabilities, typically employing formats that allow for a wide range of magnitudes and precision. The primary purpose of real data types is to enable the representation and computation of continuous quantities encountered in real-world applications, such as physical measurements (e.g., lengths, temperatures), probabilities in statistical models, and scientific data in simulations. These types support arithmetic operations like addition, multiplication, and division on approximate real values, facilitating numerical computations in fields like engineering, physics, and finance where exact integer representations would be insufficient. By providing a means to handle fractional parts, real types bridge the gap between discrete computational models and the continuous nature of many phenomena, though their approximations introduce potential rounding errors that must be managed in precise calculations. In contrast to integer data types, which are limited to whole numbers without fractional components, real data types explicitly accommodate decimals and numbers through , allowing for more versatile modeling of non-discrete data. For instance, integers cannot represent values like 3.14159 directly, whereas real types can approximate them to a specified precision, essential for tasks involving ratios or transcendental functions. A practical example is the use of the double type in C++, a common real data type that typically provides double-precision floating-point storage conforming to the standard, capable of representing approximately 15 decimal digits of precision. The following code snippet demonstrates calculating an approximation of π using the double type:

cpp

#include <iostream> #include <cmath> int main() { double pi_approx = 4.0 * atan(1.0); // Approximates π using arctangent std::cout << "Approximation of π: " << pi_approx << std::endl; return 0; }

#include <iostream> #include <cmath> int main() { double pi_approx = 4.0 * atan(1.0); // Approximates π using arctangent std::cout << "Approximation of π: " << pi_approx << std::endl; return 0; }

This outputs an approximation like 3.14159, illustrating how real types handle irrational constants in computations. Similarly, computing the square root of 2 with sqrt(2.0) yields about 1.41421, showcasing the type's utility for irrational results beyond integer capabilities.

Historical Context

The representation of real numbers in early electronic computers relied on decimal fixed-point arithmetic, as seen in the ENIAC, completed in 1946, which used 10-digit signed accumulators operating in ten's complement for decimal calculations with a fixed decimal point. This approach allowed ENIAC to handle real numbers through its 20 accumulators, each capable of storing and performing operations on up to 10 decimal digits, prioritizing simplicity for its primary applications in ballistic computations. By the 1960s, the limitations of fixed-point systems for scientific computing prompted the adoption of floating-point arithmetic, first mass-produced in hardware with IBM's 704 system in 1954, which supported floating-point operations at speeds up to 12,000 additions per second. This innovation was integrated into FORTRAN, IBM's high-level language released in 1957, enabling programmers to express real-number computations more naturally without manual scaling, as the language automatically handled floating-point types for mathematical expressions. Floating-point units became widespread by the late 1950s, appearing in systems like the IBM 709 and 7090, facilitating broader use in engineering and physics simulations. Inconsistencies across hardware implementations, such as varying precision and rounding behaviors, led to standardization efforts in the 1980s, culminating in IEEE 754, ratified in 1985, which defined uniform binary floating-point formats to ensure portability and reproducibility in computations. William Kahan, a professor at the University of California, Berkeley, played a pivotal role as chair of the IEEE 754 committee, advocating for features like gradual underflow and fused multiply-add operations to mitigate common arithmetic pitfalls, earning him the 1989 ACM Turing Award for this work. The standard addressed prior fragmentation by mandating consistent behavior on diverse platforms, dramatically improving reliability in scientific software. Post-2000 revisions to IEEE 754 extended its scope, with the 2008 update introducing quadruple-precision binary formats (128 bits) for applications requiring ultra-high accuracy, such as climate modeling, and decimal floating-point formats to align better with human-readable decimal inputs in financial systems. The 2019 revision provided minor clarifications, defect fixes, and enhancements such as new recommended operations for improved computational reliability, while maintaining backward compatibility.

Mathematical Foundations

Real Numbers in Mathematics

The real numbers, denoted R\mathbb{R}, form the unique (up to isomorphism) complete ordered field, encompassing both rational and irrational numbers to provide a continuous extension of the . This structure ensures that R\mathbb{R} satisfies the field axioms for addition and multiplication, including closure under these operations, associativity, commutativity, the existence of additive and multiplicative identities (0 and 1, respectively), additive inverses for all elements, and multiplicative inverses for all non-zero elements, along with the distributive property of multiplication over addition. Formally, for all x,y,zRx, y, z \in \mathbb{R}, (x+y)+z=x+(y+z),x+y=y+x,x+0=x,x+x=0,(xy)z=x(yz),xy=yx,x1=x,x0    y(xy=1),x(y+z)=xy+xz.\begin{align*} &(x + y) + z &= x + (y + z), & &x + y = y + x, & &x + 0 = x, & &-x + x = 0, \\ &(x \cdot y) \cdot z &= x \cdot (y \cdot z), & &x \cdot y = y \cdot x, & &x \cdot 1 = x, & &x \neq 0 \implies \exists y (x \cdot y = 1), \\ &x \cdot (y + z) &= x \cdot y + x \cdot z. \end{align*} Additionally, R\mathbb{R} is equipped with a total order << compatible with the field operations, meaning it is transitive, and for all x,yRx, y \in \mathbb{R}, exactly one of x<yx < y, x=yx = y, or x>yx > y holds, with closure under the order (if x<yx < y, then x+z<y+zx + z < y + z) and preservation under positive multiplication (if x<yx < y and 0<z0 < z, then xz<yzx z < y z). The completeness property distinguishes R\mathbb{R} from other ordered fields, guaranteeing that every non-empty subset bounded above has a least upper bound in R\mathbb{R}, or equivalently, every Cauchy sequence of real numbers converges to a limit in R\mathbb{R}. Key properties of R\mathbb{R} include its density: between any two distinct real numbers a<ba < b, there exists another real number cc such that a<c<ba < c < b. This follows directly from the ordered field structure, as c=(a+b)/2c = (a + b)/2 satisfies the inequality. The set R\mathbb{R} is also uncountable, as demonstrated by Cantor's diagonal argument, which constructs a real number not in any purported countable enumeration of R\mathbb{R} by differing in at least one decimal place from each listed number, proving that R>0|\mathbb{R}| > \aleph_0. The real numbers partition into subsets based on their algebraic properties. The rational numbers Q\mathbb{Q} consist of all numbers expressible as p/qp/q where p,qZp, q \in \mathbb{Z} and q0q \neq 0, forming a countable dense subfield of R\mathbb{R}. Irrational numbers, such as 2\sqrt{2}
Add your contribution
Related Hubs
User Avatar
No comments yet.