Mail-SpamCannibal

 view release on metacpan or  search on metacpan

DNSBLserver/extra_docs/rfc1982.txt  view on Meta::CPAN

        (i1 < i2 and i2 - i1 < 2^(SERIAL_BITS - 1)) or
        (i1 > i2 and i1 - i2 > 2^(SERIAL_BITS - 1))

   s1 is said to be greater than s2 if, and only if, s1 is not equal to
   s2, and

        (i1 < i2 and i2 - i1 > 2^(SERIAL_BITS - 1)) or
        (i1 > i2 and i1 - i2 < 2^(SERIAL_BITS - 1))

   Note that there are some pairs of values s1 and s2 for which s1 is
   not equal to s2, but for which s1 is neither greater than, nor less
   than, s2.  An attempt to use these ordering operators on such pairs
   of values produces an undefined result.

   The reason for this is that those pairs of values are such that any
   simple definition that were to define s1 to be less than s2 where
   (s1, s2) is such a pair, would also usually cause s2 to be less than
   s1, when the pair is (s2, s1).  This would mean that the particular
   order selected for a test could cause the result to differ, leading
   to unpredictable implementations.

   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

        s1 < s2 and (s1 + 1) > (s2 + 1)

   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.  Usually this will mean
   avoiding allowing those particular pairs of numbers to co-exist.

   The relationships greater than or equal to, and less than or equal
   to, follow in the natural way from the above definitions.

4. Corollaries

   These definitions give rise to some results of note.

4.1. Corollary 1

   For any sequence number s and any integer n such that addition of n
   to s is well defined, (s + n) >= s.  Further (s + n) == s only when
   n == 0, in all other defined cases, (s + n) > s.

4.2. Corollary 2

   If s' is the result of adding the non-zero integer n to the sequence
   number s, and m is another integer from the range defined as able to
   be added to a sequence number, and s" is the result of adding m to
   s', then it is undefined whether s" is greater than, or less than s,
   though it is known that s" is not equal to s.

4.3. Corollary 3

   If s" from the previous corollary is further incremented, then there
   is no longer any known relationship between the result and s.

4.4. Corollary 4

   If in corollary 2 the value (n + m) is such that addition of the sum
   to sequence number s would produce a defined result, then corollary 1

   applies, and s" is known to be greater than s.

5. Examples

5.1. A trivial example

   The simplest meaningful serial number space has SERIAL_BITS == 2.  In

   this space, the integers that make up the serial number space are 0,
   1, 2, and 3.  That is, 3 == 2^SERIAL_BITS - 1.

   In this space, the largest integer that it is meaningful to add to a
   sequence number is 2^(SERIAL_BITS - 1) - 1, or 1.

   Then, as defined 0+1 == 1, 1+1 == 2, 2+1 == 3, and 3+1 == 0.
   Further, 1 > 0, 2 > 1, 3 > 2, and 0 > 3.  It is undefined whether
   2 > 0 or 0 > 2, and whether 1 > 3 or 3 > 1.

5.2. A slightly larger example

   Consider the case where SERIAL_BITS == 8.  In this space the integers

   that make up the serial number space are 0, 1, 2, ... 254, 255.
   255 == 2^SERIAL_BITS - 1.

   In this space, the largest integer that it is meaningful to add to a
   sequence number is 2^(SERIAL_BITS - 1) - 1, or 127.

   Addition is as expected in this space, for example: 255+1 == 0,
   100+100 == 200, and 200+100 == 44.

   Comparison is more interesting, 1 > 0, 44 > 0, 100 > 0, 100 > 44,
   200 > 100, 255 > 200, 0 > 255, 100 > 255, 0 > 200, and 44 > 200.

   Note that 100+100 > 100, but that (100+100)+100 < 100.  Incrementing
   a serial number can cause it to become "smaller".  Of course,
   incrementing by a smaller number will allow many more increments to
   be made before this occurs.  However this is always something to be
   aware of, it can cause surprising errors, or be useful as it is the
   only defined way to actually cause a serial number to decrease.

   The pairs of values 0 and 128, 1 and 129, 2 and 130, etc, to 127 and
   255 are not equal, but in each pair, neither number is defined as
   being greater than, or less than, the other.

   It could be defined (arbitrarily) that 128 > 0, 129 > 1,
   130 > 2, ..., 255 > 127, by changing the comparison operator
   definitions, as mentioned above.  However note that that would cause
   255 > 127, while (255 + 1) < (127 + 1), as 0 < 128.  Such a
   definition, apart from being arbitrary, would also be more costly to
   implement.

6. Citation

   As this defined arithmetic may be useful for purposes other than for
   the DNS serial number, it may be referenced as Serial Number
   Arithmetic from RFC1982.  Any such reference shall be taken as
   implying that the rules of sections 2 to 5 of this document apply to
   the stated values.



( run in 2.116 seconds using v1.01-cache-2.11-cpan-2398b32b56e )