Floating-point arithmetic: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit Advanced mobile edit
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 307:
==Representable numbers, conversion and rounding {{anchor|Representable numbers}}==
 
By their nature, all numbers expressed in floating-point format are [[rational number]]s with a terminating expansion in the relevant base (for example, a terminating decimal expansion in base-10, or a terminating binary expansion in base-2). Irrational numbers, such as [[Pi|π]] or √2<math display=inline>\sqrt{2}</math>, or non-terminating rational numbers, must be approximated. The number of digits (or bits) 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 (it would be rounded to one of the two straddling representable values, 12345678&nbsp;×&nbsp;10<sup>1</sup> or 12345679&nbsp;×&nbsp;10<sup>1</sup>), the same applies to [[Repeating decimal|non-terminating digits]] (.{{overline|5}} to be rounded to either .55555555 or .55555556).
 
When a number is represented in some format (such as a character string) 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''.