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 other representation. Most scientific computation uses binary floating-point arithmetic, often a 64-bit representation with around 16 decimal digits of precision. Real numbers satisfy the usual rules of arithmetic, but floating-point numbers do not. The field of numerical analysis studies the stability and accuracy of numerical algorithms implemented with approximate arithmetic.
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 accept the existence of only those reals that are computable. The set of definable numbers is broader, but still only countable.
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 in base ten with five digits of precision:
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 precision, the sum 12.345 + 1.0001 = 13.3451 might be rounded to 13.345.
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 require fast processing times. The result of this dynamic range is that the numbers that can be represented are not uniformly spaced; the difference between two consecutive representable numbers varies with their exponent.
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 represents an integer and the unstated radix point would be off the right-hand end of the string, next to the least significant digit. In fixed-point systems, a position in the string is specified for the radix point. So a fixed-point scheme might use a string of 8 decimal digits with the decimal point in the middle, whereby "00012345" would represent 0001.2345.
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 orbital period of Jupiter's moon Io is 152,853.5047 seconds, a value that would be represented in standard-form scientific notation as 1.528535047×105 seconds.
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 exponent is negative.
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 give 1.528535047×105, or 152,853.5047. In storing such a number, the base need not be stored, since it will be the same for the entire range of supported numbers, and can thus be inferred.
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 can be represented exactly using a decimal base . However, 1/3 cannot be represented exactly by either binary or decimal , but in base 3, it is trivial . The occasions on which infinite expansions occur depend on the base and its prime factors.
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 is 1 in this example, is added to the integer formed by the leftmost 24 bits, yielding:
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 rule is variously called the leading bit convention, the implicit bit convention, the hidden bit convention, or the assumed bit convention.
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 fixed-point operations in this machine were initially faster than those of many competing computers.
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 of the Intel i486 in 1989 that general-purpose personal computers had floating-point capability in hardware as a standard feature.
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 modern z/Architecture systems. In 1998, IBM implemented IEEE-compatible binary floating-point arithmetic in its mainframes; in 2005, IBM also added IEEE-compatible decimal floating-point arithmetic.
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 representations, and the rounding behavior and general accuracy of operations. Floating-point compatibility across multiple computing systems was in desperate need of standardization by the early 1980s, leading to the creation of the IEEE 754 standard once the 32-bit word had become commonplace. This standard was significantly based on a proposal from Intel, which was designing the i8087 numerical coprocessor; Motorola, which was designing the 68000 around the same time, gave significant input as well.
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 component, which attaches outstandingly wider range to the number.
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 IEEE 754 binary format. The Cray T90 series had an IEEE version, but the SV1 still uses Cray floating-point format.
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 sometimes used for purely integer data, to get 53-bit integers on platforms that have double-precision floats but only 32-bit integers.
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 −∞, and they are ordered in the same way as their values .
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 for single precision, for double, or for quad. Normal numbers exclude subnormal values, zeros, infinities, and NaNs.
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 has 113.
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 represented exactly. For example, the decimal number 123456789 cannot be exactly represented if only eight decimal digits of precision are available , the same applies to non-terminating digits .
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 there is not an exact representation then the conversion requires a choice of which floating-point number to use to represent the original value. The representation chosen will have a different value from the original, and the value thus adjusted is called the rounded value.
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 other than 2 will have an infinite binary expansion. This means that numbers that appear to be short and exact when written in decimal format may need to be approximated when converted to binary floating-point. For example, the decimal number 0.1 is not representable in binary floating-point of any finite precision; the exact binary representation would have a "1100" sequence continuing endlessly:
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 with a base-2 exponent part of 0, i.e. numbers with an absolute value higher than or equal to 1 but lower than 2, an ULP is exactly 2−23 or about 10−7 in single precision, and exactly 2−53 or about 10−16 in double precision. The mandated behavior of IEEE-compliant hardware is that the result be within one-half of a ULP.
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 rounding schemes . Historically, truncation was the typical approach. Since the introduction of IEEE 754, the default method is more commonly used. This method rounds the ideal result of an arithmetic operation to the nearest representable value, and gives that representation as the result. In the case of a tie, the value that would make the significand end in an even digit is chosen. The IEEE 754 standard requires the same rounding to be applied to all fundamental algebraic operations, including square root and conversions, when there is a numeric result. It means that the results of IEEE 754 operations are completely determined in all bits of the result, except for the representation of NaNs.
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 substantially between rounding to + and − infinity then it is likely numerically unstable and affected by round-off error.
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 the precision of the operands.: 218–220
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.000000 of the approximations. In extreme cases, all significant digits of precision can be lost. This cancellation illustrates the danger in assuming that all of the digits of a computed result are meaningful. Dealing with the consequences of these errors is a topic in numerical analysis; see also Accuracy problems.
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 is needed to differentiate them from integers. Other languages do not have an integer type , or allow overloading of numeric types . In these cases, digit strings such as 123 may also be floating-point literals.
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 allows for testing of exceptional conditions to be delayed until after a full floating-point expression or subroutine: without them exceptional conditions that could not be otherwise ignored would require explicit testing immediately after every floating-point operation. By default, an operation always returns a result according to specification without interrupting computation. For instance, 1/0 returns +∞, while also setting the divide-by-zero flag bit .
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 have been updated to specify methods to access and change status flag bits. The 2008 version of the IEEE 754 standard now specifies a few operations for accessing and handling the arithmetic flag bits. The programming model is based on a single thread of execution and use of them by multiple threads has to be handled by a means outside of the standard .
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 start point.
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 represented in binary as e = −4; s = 110011001100110011001101, which is
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 computation in C: