qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Eric Blake <eblake@redhat.com>, 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: Sat, 13 Mar 2021 15:48:43 -0600	[thread overview]
Message-ID: <f5648ec4-2a02-2c4e-a865-5c0fcda04436@linaro.org> (raw)
In-Reply-To: <20210311200702.1302855-1-eblake@redhat.com>

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.


> 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).


r~


  reply	other threads:[~2021-03-13 21:49 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 [this message]
2021-03-15 11:33   ` Eric Blake
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=f5648ec4-2a02-2c4e-a865-5c0fcda04436@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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).