7 * we want to test a refid format of:
10 * where x.y.z are 24 bits containing 2 (signed) integer bits
11 * and 22 fractional bits.
13 * we want functions to convert to/from this format, with unit tests.
15 * Interesting test cases include:
25 l_fp convertRefIDToLFP(uint32_t r);
26 uint32_t convertLFPToRefID(l_fp num);
30 * The smear data in the refid is the bottom 3 bytes of the refid,
35 convertRefIDToLFP(uint32_t r)
41 printf("%03d %08x: ", (r >> 24) & 0xFF, (r & 0x00FFFFFF) );
43 temp.l_uf = (r << 10); /* 22 fractional bits */
45 temp.l_ui = (r >> 22) & 0x3;
46 temp.l_ui |= ~(temp.l_ui & 2) + 1;
53 convertLFPToRefID(l_fp num)
57 /* round the input with the highest bit to shift out from the
58 * fraction, then keep just two bits from the integral part.
60 * TODO: check for overflows; should we clamp/saturate or just
66 /* combine integral and fractional part to 24 bits */
67 temp = (num.l_ui << 22) | (num.l_uf >> 10);
69 /* put in the leading 254.0.0.0 */
70 temp |= UINT32_C(0xFE000000);
72 printf("%03d %08x: ", (temp >> 24) & 0xFF, (temp & 0x00FFFFFF) );
77 /* Tests start here */
79 void rtol(uint32_t r);
88 l = convertRefIDToLFP(htonl(r));
89 printf("refid %#x, smear %s\n", r, lfptoa(&l, 8));
95 void rtoltor(uint32_t r);
103 l = convertRefIDToLFP(htonl(r));
105 r = convertLFPToRefID(l);
106 printf("smear %s, refid %#.8x\n", lfptoa(&l, 8), ntohl(r));
121 r = convertLFPToRefID(l);
122 printf("smear %s, refid %#.8x\n", lfptoa(&l, 8), ntohl(r));
169 rc = atolfp("-.932087", &l);
172 printf("%x -> %d.%d.%d.%d\n",