qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 11/11] cutils: Improve qemu_strtosz handling of fractions


From: Hanna Czenczek
Subject: Re: [PATCH 11/11] cutils: Improve qemu_strtosz handling of fractions
Date: Wed, 10 May 2023 09:48:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0

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;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]