Number
int64
1
7.61k
Text
stringlengths
2
3.11k
4,501
Instead, computers typically work with finite-precision approximations called floating-point numbers, a representation similar to scientific notation. The achievable precision is limited by the data storage space allocated for each number, whether as fixed-point, floating-point, or arbitrary-precision numbers, or some ...
4,502
A real number is called computable if there exists an algorithm that yields its digits. Because there are only countably many algorithms, but an uncountable number of reals, almost all real numbers fail to be computable. Moreover, the equality of two computable numbers is an undecidable problem. Some constructivists ac...
4,503
In set theory, specifically descriptive set theory, the Baire space is used as a surrogate for the real numbers since the latter have some topological properties that are a technical inconvenience. Elements of Baire space are referred to as "reals".
4,504
In mathematics, real is used as an adjective, meaning that the underlying field is the field of the real numbers . For example, real matrix, real polynomial and real Lie algebra. The word is also used as a noun, meaning a real number .
4,505
The real numbers can be generalized and extended in several different directions:
4,506
In computing, floating-point arithmetic is arithmetic that represents subsets of real numbers using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. Numbers of this form are called floating-point numbers.: 3 : 10  For example, 12.345 is a floating-point number i...
4,507
However, unlike 12.345, 12.3456 is not a floating-point number in base ten with five digits of precision—it needs six digits of precision; the nearest floating-point number with only five digits is 12.346. In practice, most floating-point systems use base two, though base ten is also common.
4,508
Floating-point arithmetic operations, such as addition and division, approximate the corresponding real number arithmetic operations by rounding any result that is not a floating-point number itself to a nearby floating-point number.: 22 : 10  For example, in a floating-point arithmetic with five base-ten digits of pre...
4,509
The term floating point refers to the fact that the number's radix point can "float" anywhere to the left, right, or between the significant digits of the number. This position is indicated by the exponent, so floating point can be considered a form of scientific notation.
4,510
A floating-point system can be used to represent, with a fixed number of digits, numbers of very different orders of magnitude — such as the number of meters between galaxies or between protons in an atom. For this reason, floating-point arithmetic is often used to allow very small and very large real numbers that req...
4,511
Over the years, a variety of floating-point representations have been used in computers. In 1985, the IEEE 754 Standard for Floating-Point Arithmetic was established, and since the 1990s, the most commonly encountered representations are those defined by the IEEE.
4,512
The speed of floating-point operations, commonly measured in terms of FLOPS, is an important characteristic of a computer system, especially for applications that involve intensive mathematical calculations.
4,513
A floating-point unit is a part of a computer system specially designed to carry out operations on floating-point numbers.
4,514
A number representation specifies some way of encoding a number, usually as a string of digits.
4,515
There are several mechanisms by which strings of digits can represent numbers. In standard mathematical notation, the digit string can be of any length, and the location of the radix point is indicated by placing an explicit "point" character there. If the radix point is not specified, then the string implicitly repre...
4,516
In scientific notation, the given number is scaled by a power of 10, so that it lies within a specific range—typically between 1 and 10, with the radix point appearing immediately after the first digit. As a power of ten, the scaling factor is then indicated separately at the end of the number. For example, the orbit...
4,517
Floating-point representation is similar in concept to scientific notation. Logically, a floating-point number consists of:
4,518
To derive the value of the floating-point number, the significand is multiplied by the base raised to the power of the exponent, equivalent to shifting the radix point from its implied position by a number of places equal to the value of the exponent—to the right if the exponent is positive or to the left if the expone...
4,519
Using base-10 as an example, the number 152,853.5047, which has ten decimal digits of precision, is represented as the significand 1,528,535,047 together with 5 as the exponent. To determine the actual value, a decimal point is placed after the first digit of the significand and the result is multiplied by 105 to giv...
4,520
where s is the significand , p is the precision , b is the base , and e is the exponent.
4,521
Historically, several number bases have been used for representing floating-point numbers, with base two being the most common, followed by base ten , and other less common varieties, such as base sixteen , base eight , base four , base three and even base 256 and base 65,536.
4,522
A floating-point number is a rational number, because it can be represented as one integer divided by another; for example 1.45×103 is ×1000 or 145,000/100. The base determines the fractions that can be represented; for instance, 1/5 cannot be represented exactly as a floating-point number using a binary base, but 1/5 ...
4,523
In this binary expansion, let us denote the positions from 0 to 32 . The 24-bit significand will stop at position 23, shown as the underlined bit 0 above. The next bit, at position 24, is called the round bit or rounding bit. It is used to round the 33-bit approximation to the nearest 24-bit number . This bit, which i...
4,524
When this is stored in memory using the IEEE 754 encoding, this becomes the significand s. The significand is assumed to have a binary point to the right of the leftmost bit. So, the binary representation of π is calculated from left-to-right as follows:
4,525
where p is the precision , n is the position of the bit of the significand from the left and e is the exponent .
4,526
It can be required that the most significant digit of the significand of a non-zero number be non-zero . This process is called normalization. For binary formats , this non-zero digit is necessarily 1. Therefore, it does not need to be represented in memory, allowing the format to have one more bit of precision. This r...
4,527
The floating-point representation is by far the most common way of representing in computers an approximation to real numbers. However, there are alternatives:
4,528
The first commercial computer with floating-point hardware was Zuse's Z4 computer, designed in 1942–1945. In 1946, Bell Laboratories introduced the Model V, which implemented decimal floating-point numbers.
4,529
The Pilot ACE has binary floating-point arithmetic, and it became operational in 1950 at National Physical Laboratory, UK. Thirty-three were later sold commercially as the English Electric DEUCE. The arithmetic is actually implemented in software, but with a one megahertz clock rate, the speed of floating-point and fix...
4,530
The mass-produced IBM 704 followed in 1954; it introduced the use of a biased exponent. For many decades after that, floating-point hardware was typically an optional feature, and computers that had it were said to be "scientific computers", or to have "scientific computation" capability ). It was not until the launch...
4,531
The UNIVAC 1100/2200 series, introduced in 1962, supported two floating-point representations:
4,532
The IBM 7094, also introduced in 1962, supported single-precision and double-precision representations, but with no relation to the UNIVAC's representations. Indeed, in 1964, IBM introduced hexadecimal floating-point representations in its System/360 mainframes; these same representations are still available for use in...
4,533
Initially, computers used many different representations for floating-point numbers. The lack of standardization at the mainframe level was an ongoing problem by the early 1970s for those writing and maintaining higher-level source code; these manufacturer floating-point standards differed in the word sizes, the repres...
4,534
In 1989, mathematician and computer scientist William Kahan was honored with the Turing Award for being the primary architect behind this proposal; he was aided by his student Jerome Coonen and a visiting professor, Harold Stone.
4,535
Among the x86 innovations are these:
4,536
A floating-point number consists of two fixed-point components, whose range depends exclusively on the number of bits or digits in their representation. Whereas components linearly depend on their range, the floating-point range linearly depends on the significand range and exponentially on the range of exponent compon...
4,537
On a typical computer system, a double-precision binary floating-point number has a coefficient of 53 bits , an exponent of 11 bits, and 1 sign bit. Since 210 = 1024, the complete range of the positive normal floating-point numbers in this format is from 2−1022 ≈ 2 × 10−308 to approximately 21024 ≈ 2 × 10308.
4,538
The number of normal floating-point numbers in a system where
4,539
There is a smallest positive normal floating-point number,
4,540
which has a 1 as the leading digit and 0 for the remaining digits of the significand, and the smallest possible value for the exponent.
4,541
There is a largest floating-point number,
4,542
which has B − 1 as the value for each digit of the significand and the largest possible value for the exponent.
4,543
In addition, there are representable values strictly between −UFL and UFL. Namely, positive and negative zeros, as well as subnormal numbers.
4,544
The IEEE standardized the computer representation for binary floating-point numbers in IEEE 754 in 1985. This first standard is followed by almost all modern machines. It was revised in 2008. IBM mainframes support IBM's own hexadecimal floating point format and IEEE 754-2008 decimal floating point in addition to the ...
4,545
The standard provides for many closely related formats, differing in only a few details. Five of these formats are called basic formats, and others are termed extended precision formats and extendable precision format. Three formats are especially widely used in computer hardware and languages:
4,546
Increasing the precision of the floating-point representation generally reduces the amount of accumulated round-off error caused by intermediate calculations. Other IEEE formats include:
4,547
Any integer with absolute value less than 224 can be exactly represented in the single-precision format, and any integer with absolute value less than 253 can be exactly represented in the double-precision format. Furthermore, a wide range of powers of 2 times such a number can be represented. These properties are some...
4,548
The standard specifies some special values, and their representation: positive infinity , negative infinity , a negative zero distinct from ordinary zero, and "not a number" values .
4,549
Comparison of floating-point numbers, as defined by the IEEE standard, is a bit different from usual integer comparison. Negative and positive zero compare equal, and every NaN compares unequal to every value, including itself. All finite floating-point numbers are strictly smaller than +∞ and strictly greater than −∞,...
4,550
Floating-point numbers are typically packed into a computer datum as the sign bit, the exponent field, and the significand or mantissa, from left to right. For the IEEE 754 binary formats which have extant hardware implementations, they are apportioned as follows:
4,551
While the exponent can be positive or negative, in binary formats it is stored as an unsigned number that has a fixed "bias" added to it. Values of all 0s in this field are reserved for the zeros and subnormal numbers; values of all 1s are reserved for the infinities and NaNs. The exponent range for normal numbers is ...
4,552
In the IEEE binary interchange formats the leading 1 bit of a normalized significand is not actually stored in the computer datum. It is called the "hidden" or "implicit" bit. Because of this, the single-precision format actually has a significand with 24 bits of precision, the double-precision format has 53, and quad ...
4,553
For example, it was shown above that π, rounded to 24 bits of precision, has:
4,554
The sum of the exponent bias and the exponent is 128, so this is represented in the single-precision format as
4,555
An example of a layout for 32-bit floating point is
4,556
and the 64-bit layout is similar.
4,557
In addition to the widely used IEEE 754 standard formats, other floating-point formats are used, or have been used, in certain domain-specific areas.
4,558
By their nature, all numbers expressed in floating-point format are rational numbers with a terminating expansion in the relevant base . Irrational numbers, such as π or √2, or non-terminating rational numbers, must be approximated. The number of digits of precision also limits the set of rational numbers that can be ...
4,559
When a number is represented in some format which is not a native floating-point representation supported in a computer implementation, then it will require a conversion before it can be used in that implementation. If the number can be represented exactly in the floating-point format then the conversion is exact. If ...
4,560
Whether or not a rational number has a terminating expansion depends on the base. For example, in base-10 the number 1/2 has a terminating expansion while the number 1/3 does not . In base-2 only rationals with denominators that are powers of 2 are terminating. Any rational with a denominator that has a prime factor ...
4,561
where, as previously, s is the significand and e is the exponent.
4,562
When rounded to 24 bits this becomes
4,563
which is actually 0.100000001490116119384765625 in decimal.
4,564
As a further example, the real number π, represented in binary as an infinite sequence of bits is
4,565
when approximated by rounding to a precision of 24 bits.
4,566
In binary single-precision floating-point, this is represented as s = 1.10010010000111111011011 with e = 1. This has a decimal value of
4,567
whereas a more accurate approximation of the true value of π is
4,568
The result of rounding differs from the true value by about 0.03 parts per million, and matches the decimal representation of π in the first 7 digits. The difference is the discretization error and is limited by the machine epsilon.
4,569
The arithmetical difference between two consecutive representable floating-point numbers which have the same exponent is called a unit in the last place . For example, if there is no representable number lying between the representable numbers 1.45a70c22hex and 1.45a70c24hex, the ULP is 2×16−8, or 2−31. For numbers wit...
4,570
Rounding is used when the exact result of a floating-point operation would need more digits than there are digits in the significand. IEEE 754 requires correct rounding: that is, the rounded result is as if infinitely precise arithmetic was used to compute the value and then rounded . There are several different round...
4,571
Alternative rounding options are also available. IEEE 754 specifies the following rounding modes:
4,572
Alternative modes are useful when the amount of error being introduced must be bounded. Applications that require a bounded error are multi-precision floating-point, and interval arithmetic. The alternative rounding modes are also useful in diagnosing numerical instability: if the results of a subroutine vary substanti...
4,573
Converting a double-precision binary floating-point number to a decimal string is a common operation, but an algorithm producing results that are both accurate and minimal did not appear in print until 1990, with Steele and White's Dragon4. Some of the improvements since then include:
4,574
Many modern language runtimes use Grisu3 with a Dragon4 fallback.
4,575
The problem of parsing a decimal string into a binary FP representation is complex, with an accurate parser not appearing until Clinger's 1990 work . Further work has likewise progressed in the direction of faster parsing.
4,576
For ease of presentation and understanding, decimal radix with 7 digit precision will be used in the examples, as in the IEEE 754 decimal32 format. The fundamental principles are the same in any radix or precision, except that normalization is optional . Here, s denotes the significand and e denotes the exponent.
4,577
A simple method to add floating-point numbers is to first represent them with the same exponent. In the example below, the second number is shifted right by three digits, and one then proceeds with the usual addition method:
4,578
In detail:
4,579
This is the true result, the exact sum of the operands. It will be rounded to seven digits and then normalized if necessary. The final result is
4,580
The lowest three digits of the second operand are essentially lost. This is round-off error. In extreme cases, the sum of two non-zero numbers may be equal to one of them:
4,581
In the above conceptual examples it would appear that a large number of extra digits would need to be provided by the adder to ensure correct rounding; however, for binary addition or subtraction using careful implementation techniques only a guard bit, a rounding bit and one extra sticky bit need to be carried beyond ...
4,582
Another problem of loss of significance occurs when approximations to two nearly equal numbers are subtracted. In the following example e = 5; s = 1.234571 and e = 5; s = 1.234567 are approximations to the rationals 123457.1467 and 123456.659.
4,583
The floating-point difference is computed exactly because the numbers are close—the Sterbenz lemma guarantees this, even in case of underflow when gradual underflow is supported. Despite this, the difference of the original numbers is e = −1; s = 4.877000, which differs more than 20% from the difference e = −1; s = 4.0...
4,584
To multiply, the significands are multiplied while the exponents are added, and the result is rounded and normalized.
4,585
Similarly, division is accomplished by subtracting the divisor's exponent from the dividend's exponent, and dividing the dividend's significand by the divisor's significand.
4,586
There are no cancellation or absorption problems with multiplication or division, though small errors may accumulate as operations are performed in succession. In practice, the way these operations are carried out in digital logic can be quite complex . For a fast, simple method, see the Horner method.
4,587
Literals for floating-point numbers depend on languages. They typically use e or E to denote scientific notation. The C programming language and the IEEE 754 standard also define a hexadecimal literal syntax with a base-2 exponent instead of 10. In languages like C, when the decimal exponent is omitted, a decimal point...
4,588
Examples of floating-point literals are:
4,589
Floating-point computation in a computer can run into three kinds of problems:
4,590
Prior to the IEEE standard, such conditions usually caused the program to terminate, or triggered some kind of trap that the programmer might be able to catch. How this worked was system-dependent, meaning that floating-point programs were not portable.
4,591
Here, the required default method of handling exceptions according to IEEE 754 is discussed . Arithmetic exceptions are required to be recorded in "sticky" status flag bits. That they are "sticky" means that they are not reset by the next operation, but stay set until explicitly reset. The use of "sticky" flags thus ...
4,592
The original IEEE 754 standard, however, failed to recommend operations to handle such sets of arithmetic exception flag bits. So while these were implemented in hardware, initially programming language implementations typically did not provide a means to access them . Over time some programming language standards hav...
4,593
IEEE 754 specifies five arithmetic exceptions that are to be recorded in the status flags :
4,594
Overflow and invalid exceptions can typically not be ignored, but do not necessarily represent errors: for example, a root-finding routine, as part of its normal operation, may evaluate a passed-in function at values outside of its domain, returning NaN and an invalid exception flag to be ignored until finding a useful...
4,595
The fact that floating-point numbers cannot accurately represent all real numbers, and that floating-point operations cannot accurately represent true arithmetic operations, leads to many surprising situations. This is related to the finite precision with which computers generally represent numbers.
4,596
For example, the decimal numbers 0.1 and 0.01 cannot be represented exactly as binary floating-point numbers. In the IEEE 754 binary32 format with its 24-bit significand, the result of attempting to square the approximation to 0.1 is neither 0.01 nor the representable number closest to it. The decimal number 0.1 is rep...
4,597
Squaring this number gives
4,598
Squaring it with rounding to the 24-bit precision gives
4,599
But the representable number closest to 0.01 is
4,600
Also, the non-representability of π means that an attempted computation of tan will not yield a result of infinity, nor will it even overflow in the usual floating-point formats . It is simply not possible for standard floating-point hardware to attempt to compute tan, because π/2 cannot be represented exactly. This c...