Skip to main content

4. A Compact Time Representation with Logarithmic Range

4. A Compact Time Representation with Logarithmic Range

This document uses the compact time representation described in "Information-Centric Networking (ICN) Adaptation to Low-Power Wireless Personal Area Networks (LoWPANs)" (see Section 7 of [RFC9139]) that was inspired by [RFC5497] and [IEEE.754.2019]. Its logarithmic encoding supports a representation ranging from milliseconds to years. Figure 1 depicts the logarithmic nature of this time representation.

 || |  |   |    |     |      |       |        |         |          |
+-----------------------------------------------------------------+
milliseconds years

Figure 1: A logarithmic range representation allows for higher precision in the smaller time ranges and still supports large time deltas.

Time codes encode exponent and mantissa values in a single byte. In contrast to the representation in [IEEE.754.2019], time codes only encode non-negative numbers and hence do not include a separate bit to indicate integer signedness. Figure 2 shows the configuration of a time code: an exponent width of 5 bits, and a mantissa width of 3 bits.

              <---          one byte wide          --->
+----+----+----+----+----+----+----+----+
| exponent (b) | mantissa (a) |
+----+----+----+----+----+----+----+----+
0 1 2 3 4 5 6 7

Figure 2: A time code with exponent and mantissa to encode a logarithmic range time representation.

The base unit for time values is seconds. A time value is calculated using the following formula (adopted from [RFC5497] and [RFC9139]), where (a) represents the mantissa, (b) the exponent, and (C) a constant factor set to C := 1/32.

Subnormal (b == 0): (0 + a/8) * 2 * C

Normalized (b > 0): (1 + a/8) * 2^b * C

The subnormal form provides a gradual underflow between zero and the smallest normalized number. Eight time values exist in the subnormal range [0s,~0.0546875s] with a step size of ~0.0078125s between each time value. This configuration also encodes the following convenient numbers in seconds: [1, 2, 4, 8, 16, 32, 64, ...]. Appendix A includes test vectors to illustrate the logarithmic range.

An example algorithm to encode a time value into the corresponding exponent and mantissa is given as pseudocode in Figure 3. Not all time values can be represented by a time code. For these instances, a time code is produced that represents a time value closest to and smaller than the initial time value input.

 input: float v    // time value
output: int a, b // mantissa, exponent of time code

(a, b) encode (v):

if (v == 0)
return (0, 0)

if (v < 2 * C) // subnormal
a = floor (v * 4 / C) // round down
return (a, 0)
else // normalized
if (v > (1 + 7/8) * 2^31 * C) // check bounds
return (7, 31) // return maximum
else
b = floor (log2(v / C)) // round down
a = floor ((v / (2^b * C) - 1) * 8) // round down
return (a, b)

Figure 3: Algorithm in pseudocode.

For example, no specific time code for 0.063 exists. However, this algorithm maps to the closest valid time code that is smaller than 0.063, i.e., exponent 1 and mantissa 0 (the same as for time value 0.0625).