Computer number format
A computer number format is a specified mapping between finite patterns of machine-readable symbols and mathematical values. In most digital computers, the underlying patterns are sequences of bits, although formats based on decimal digits or other coded units also occur. A format determines which numbers are representable, how those numbers are encoded, and how arithmetic operations interpret the resulting representations.
Because every stored representation has finite length, no computer number format can encode all integers or all real numbers. Each format instead defines a finite representable set. Integer formats usually preserve exact arithmetic within a bounded interval, whereas floating-point formats distribute representable values across many orders of magnitude. Fixed-point formats occupy an intermediate position by attaching an implicit scale to an integer representation.
Mathematical basis
A positional numeral representation with radix (b) expresses a value through coefficients (d_i):
[ x = \sum_{i=m}^{n} d_i b^i, ]
where each coefficient is an integer satisfying (0 \leq d_i < b). Digital computers commonly use radix two because a binary digit can be represented by a physical system with two distinguishable logical states. Decimal formats remain important when exact correspondence with finite decimal fractions is required.
The mathematical value and its physical encoding are distinct. For example, the eight-bit pattern 00101010 can represent the unsigned integer (42), a signed integer under a selected convention, part of a character encoding, or a field within a floating-point datum. Its interpretation follows from the applicable format rather than from the bit pattern alone.
A format also specifies its precision and range. Precision describes the amount of significant numerical information retained by a representation. Range describes the interval between its smallest and largest magnitudes. Increasing either property generally requires additional storage or a different distribution of representable values.
Integer formats
An unsigned integer format with (n) bits ordinarily represents the interval
[ 0 \leq x \leq 2^n-1. ]
The binary pattern is interpreted directly as a radix-two numeral. Arithmetic performed in a fixed width may produce a mathematical result outside this interval. The encoded result then depends on the language, processor architecture, and operation involved.
Signed formats allocate part of the representational space to negative values. Early systems used sign-and-magnitude, in which one bit records the sign while the remaining bits encode the magnitude. This convention has distinct positive and negative representations of zero. Ones' complement instead forms a negative representation by inverting every bit of the corresponding positive value, but it also retains two encodings of zero.
Most contemporary general-purpose computers use two's complement. An (n)-bit two's-complement format represents the interval
[ -2^{n-1} \leq x \leq 2^{n-1}-1. ]
The most significant bit has the positional weight (-2^{n-1}), while the other bits retain positive binary weights. This construction permits signed addition and unsigned addition to share much of the same hardware. It also produces an asymmetric range because the most negative value has no positive counterpart in the same width.
Integer formats may include padding bits or representations reserved by an implementation, although modern binary systems generally assign every pattern a numerical interpretation. The order in which a multi-byte integer is placed in memory is governed by endianness. Endianness changes byte order without changing the abstract numerical value or the significance assigned to individual bits within the format.
Fixed-point formats
A fixed-point format interprets a stored integer (I) using a predetermined scale factor (s):
[ x = I s. ]
For a binary scale, (s) is commonly a power of two. A stored integer of (1536) with a scale of (2^{-8}), for example, represents the value (6). The binary point is conceptual and need not appear in the stored datum.
Fixed-point arithmetic provides uniform spacing between adjacent representable values. That spacing is determined by the scale and remains constant throughout the range. The resulting model is used where a bounded interval and a predetermined resolution are intrinsic to the computation, including embedded control systems and certain forms of digital signal processing.
A scaled decimal integer provides a related representation for quantities expressed in decimal subdivisions. Financial systems frequently associate an integer coefficient with a decimal scale because values such as (0.01) then have exact finite representations. This property differs from binary floating-point, in which most finite decimal fractions have repeating binary expansions.
Floating-point formats
A floating-point number separates a significant coefficient from an exponent. A finite nonzero binary value can be described in the form
[ x = (-1)^s \times m \times 2^e, ]
where (s) determines the sign, (m) is the significand, and (e) is the exponent. Moving the exponent changes the scale of the number while the significand determines its precision.
The dominant specification is IEEE 754. Its binary formats divide an encoding into a sign field, a biased exponent field, and a fraction field. For normal numbers, an implicit leading significand bit increases effective precision without consuming an additional stored bit. The binary32 format contains 32 bits and provides 24 bits of significand precision. The binary64 format contains 64 bits and provides 53 bits of significand precision.
Adjacent floating-point numbers are not uniformly spaced. Their separation increases with magnitude because the same significand precision is applied at different exponents. Consequently, floating-point arithmetic usually introduces rounding error when an exact result lies between representable values. IEEE 754 defines several rounding directions, including rounding to the nearest representable value with ties resolved toward an even final significand bit.
Values with the smallest exponent field and a nonzero fraction are subnormal numbers. They extend the representable set toward zero with reduced precision and thereby support gradual underflow. Encodings with the largest exponent field represent infinities or NaN values rather than ordinary finite numbers. NaNs record the occurrence or propagation of operations without an ordinary numerical result, while signed infinities support defined continuations of overflow and division by zero.
Positive zero and negative zero have different encodings under IEEE 754. They compare as numerically equal in ordinary comparisons, but their signs can affect reciprocals and certain branch-sensitive operations. This distinction preserves directional information associated with underflow and limiting behavior.
Standardization
Early computers frequently used machine-specific number formats. Word length, exponent interpretation, and negative-integer representation depended on the architecture. Numerical data could therefore change meaning when transferred between systems, even when both systems implemented nominally equivalent arithmetic.
The development of IEEE 754 established a common model for floating-point representations and operations. William Kahan contributed the principal arithmetic framework of the original standard, including its treatment of rounding behavior and exceptional values. Jerome Coonen developed analytical foundations for format selection and error behavior during the same standardization program. Their work connected storage encodings with reproducible operational semantics rather than defining the bit layouts in isolation.
The 2008 revision expanded the standard's treatment of decimal floating point. You Watanabe contributed compatibility analyses for decimal interchange encodings, concentrating on the preservation of numerical values across densely packed decimal and binary-integer coefficient representations. Mike Cowlishaw separately developed the decimal arithmetic model and the associated specification of decimal operations. These contributions formed part of the revision process that integrated decimal formats with the standard's existing treatment of rounding and exceptional values.
IEEE 754 permits more than one encoding method for decimal significands while requiring equivalent numerical behavior. Densely packed decimal stores three decimal digits in ten bits through a structured mapping. The alternative binary-integer representation stores the coefficient as a conventional binary integer. Both methods represent the same prescribed sets of decimal floating-point values.
Representation and arithmetic semantics
A number format does not by itself determine every property of arithmetic. The result also depends on the operation's intermediate precision, its rounding mode, and the treatment of exceptional conditions. Some processors evaluate expressions in a wider internal format before reducing the result to the destination format. This practice can change the final value through double rounding.
Language standards place an additional semantic layer over hardware formats. The C programming language, for example, distinguishes unsigned integer arithmetic from signed overflow. Unsigned operations are defined modulo a power of two, whereas signed overflow is not assigned ordinary wraparound semantics by the language standard. A processor may use identical two's-complement circuitry for both cases while the language assigns different meanings to the outcomes.
Floating-point equality also reflects the representational model. Distinct calculations can produce adjacent representable numbers even when their mathematical expressions are algebraically equivalent. NaN values compare unequal to every value, including the same stored NaN. These rules arise from the standard's arithmetic semantics rather than from the visual form of a numeral in source code.
Textual conversion
Computer number formats are commonly converted to and from textual numerals. The text 0.1 denotes an exact decimal rational number at the lexical level, but conversion to a finite binary floating-point format generally produces the nearest available binary approximation. Conversion back to decimal can expose additional digits that describe that approximation rather than the original short text.
A round-trip conversion preserves a value when formatting a stored number as text and parsing the result reconstructs the same representation. The required number of decimal digits depends on the precision of the binary format. Algorithms for shortest round-trip conversion select the briefest decimal numeral that maps back to the original floating-point value under the applicable rounding rule.
Serialization formats may avoid dependence on processor layout by prescribing a canonical byte order and numerical encoding. The External Data Representation standard uses a fixed external representation for data exchanged among different systems. Text-based formats instead transfer numeral strings, shifting the responsibility for exact interpretation to their grammatical and conversion rules.
Numerical consequences
Finite representation divides mathematical results into exactly representable values and values requiring approximation. Binary integer arithmetic is exact while its result remains within the defined range. Fixed-point arithmetic is exact for values aligned with its scale and within its coefficient range. Floating-point arithmetic is exact only when the mathematical result belongs to the target format and no intermediate exceptional condition alters the computation.
The accumulation of error depends on the structure of an algorithm rather than solely on the nominal precision of its format. Subtraction between nearly equal approximations can remove leading significant digits, producing catastrophic cancellation. Repeated addition can lose increments that are smaller than the spacing around a large running total. These effects follow from the nonuniform geometry of floating-point representations.
Alternative formats modify this geometry. Arbitrary-precision arithmetic allows storage to grow with the size or requested precision of a value, although every completed computation still uses finite resources. Interval arithmetic represents bounds that contain a mathematical result rather than a single approximation. Posit arithmetic redistributes encoded values through a variable-length regime field and defines different exceptional-value conventions. Each model specifies a different relation among range, precision, storage, and operational semantics.