Serial number arithmetic

This task is rather more complex than it might first appear, because most algorithms use fixed-size (binary) representations for sequence numbers.

Some protocols choose to ignore these issues and simply use very large integers for their counters, in the hope that the program will be replaced (or they will retire) before the problem occurs (see Y2K).

Only unsigned binary implementations are discussed, with an arbitrary size in bits noted throughout the RFC (and below) as "SERIAL_BITS".

Thus i1 is considered less than i2 only if The algorithms presented by the RFC have at least one significant shortcoming: there are sequence numbers for which comparison is undefined.

The authors of RFC 1982 acknowledge this without offering a general solution: While it would be possible to define the test in such a way that the inequality would not have this surprising property, while being defined for all pairs of values, such a definition would be unnecessarily burdensome to implement, and difficult to understand, and would still allow cases where which is just as non-intuitive.

Thus the problem case is left undefined, implementations are free to return either result, or to flag an error, and users must take care not to depend on any particular outcome.

By mapping the unsigned sequence numbers onto signed two's complement arithmetic operations, every comparison of any sequence number is defined, and the comparison operation itself is dramatically simplified.

Most modern hardware implements signed two's complement binary arithmetic operations.