qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>, berrange@redhat.com
Subject: Re: [PATCH] utils: Reduce chance of rounding inaccuracy in qemu_strtosz.
Date: Mon, 15 Mar 2021 06:33:20 -0500	[thread overview]
Message-ID: <d9f498ab-00b8-291d-821b-66c82de90fa2@redhat.com> (raw)
In-Reply-To: <f5648ec4-2a02-2c4e-a865-5c0fcda04436@linaro.org>

On 3/13/21 3:48 PM, Richard Henderson wrote:
> On 3/11/21 2:07 PM, Eric Blake wrote:
>> +        /*
>> +         * Add in a fudge-factor (2^53 when double is IEEE format) for
>> +         * all scales less than P (2^50), so that things like
>> +         * 12.345M with unit 1000 produce 12345000 instead of
>> +         * 12344999.
>> +         */
>> +        if (mul > 1e49) {
> 
> The comment says less than, the code says greater than.

Shoot. A demonstration that I did not have an environment that actually
reproduced the bug (and my request for help in figuring out how to kick
off a gitlab CI run that would catch it).

> 
> 
>> An alternative patch might be writing (uint64_t)(fraction * mul + 0.5)
>> (that is, introduce the fudge factor after the multiplication instead
>> of before).  Preferences?
> 
> I think I would prefer this, or for further rounding error reduction,
> fma(fraction, mul, 0.5).

Indeed, fma() sounds a bit nicer at minimizing the chance for double
rounding errors.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



  reply	other threads:[~2021-03-15 11:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 20:07 [PATCH] utils: Reduce chance of rounding inaccuracy in qemu_strtosz Eric Blake
2021-03-13 21:48 ` Richard Henderson
2021-03-15 11:33   ` Eric Blake [this message]
2021-03-15 13:18     ` Richard Henderson
2021-03-15 18:07       ` Eric Blake
2021-03-15 11:28 ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9f498ab-00b8-291d-821b-66c82de90fa2@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).