MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

common/test/run-gossmap-fp16.c:105–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103/* AUTOGENERATED MOCKS END */
104
105int main(int argc, char *argv[])
106{
107 /* 5 bit exponent, 11 bit mantissa. */
108 u32 exponent, mantissa;
109
110 common_setup(argv[0]);
111
112 /* These can be represented exactly. */
113 for (exponent = 0; exponent < (1 << 5); exponent++) {
114 for (mantissa = 0; mantissa < (1 << 11); mantissa++) {
115 u64 v = ((u64)mantissa << exponent);
116 assert(fp16_to_u64(u64_to_fp16(v, false)) == v);
117 assert(fp16_to_u64(u64_to_fp16(v, true)) == v);
118 }
119 }
120
121 /* Now check round up vs down (don't use exponent 32, since that will
122 * overflow). */
123 for (exponent = 1; exponent < (1 << 5) - 1; exponent++) {
124 /* Too many bits: will require rounding */
125 mantissa = (1 << 11) + 1;
126 u64 v = ((u64)mantissa << exponent);
127
128 assert(fp16_to_u64(u64_to_fp16(v, false))
129 == ((u64)(mantissa - 1) << exponent));
130 assert(fp16_to_u64(u64_to_fp16(v, true))
131 == ((u64)(mantissa + 1) << exponent));
132 }
133
134 assert(u64_to_fp16((1ULL << (31 + 11)), false) == 65535);
135 assert(u64_to_fp16((1ULL << (31 + 11)), true) == 65535);
136
137 /* Round up works, even if it causes overflow. */
138 assert(fp16_to_u64(u64_to_fp16(0xffffffff, true)) == (1ULL << 32));
139
140 common_shutdown();
141}

Callers

nothing calls this directly

Calls 4

common_setupFunction · 0.85
fp16_to_u64Function · 0.85
u64_to_fp16Function · 0.85
common_shutdownFunction · 0.85

Tested by

no test coverage detected