On 10.05.23 09:46, Hanna Czenczek wrote:
On 09.05.23 23:28, Eric Blake wrote:
[...]
But I think the solution to that is not to treat underflow as valf =
0, but rather to alter this snippet:
- valf = (uint64_t)(fraction * 0x1p64);
+ /*
+ * If fraction was non-zero, add slop small enough that
it doesn't
+ * impact rounding, but does let us reject
"1..00000000000000000001B".
+ */
+ valf = (uint64_t)(fraction * 0x1p64) | !fraction;
so that between the ERANGE branch and this slop, valf is guaranteed
non-zero if fraction contained any non-zero digits.
I’d make it a logical || instead of |, but that sounds good, yes.
Sent too soon – exactly when sending I realized that I’m very wrong.
Still, I wouldn’t just | the 1 on, and rather make take the LoC to make it
valf = (uint64_t)(fraction * 0x1p64);
if (!valf && fraction) {
/*
* If fraction was non-zero, add slop small enough that it doesn't
* impact rounding, but does let us reject "1..00000000000000000001B".
*/
valf = 1;
}