mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Peter Ammon <corydoras@ridiculousfish.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] [PATCH] Fix printf hex float formatting with precision
Date: Fri, 12 Apr 2024 15:57:28 -0400	[thread overview]
Message-ID: <20240412195728.GE4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <F821CF10-24E5-4700-B514-62604EC9B891@ridiculousfish.com>

On Thu, Apr 11, 2024 at 06:17:25PM -0700, Peter Ammon wrote:
> if (p>=0 && p<(LDBL_MANT_DIG-1+3)/4) {
>     int re = LDBL_MANT_DIG-1-(p*4);
>     long double round = 1ULL<<re;

This expression overflows. re can be as large as 108 but 1ULL has
64-bit type.

There's probably some reasonable way to write it that works for
reasonable sizes of long double (I think it's safe to assume IEEE quad
is the max that will ever be supported), but I presume I wrote it with
the original inefficient loop to be fully general to arbitrary
precision.

It could just be written to use scalbn, I think. At the time I
probably was trying to avoid dependency on a libm that could have been
separate from libc (bad historical thing). IIRC there was a time when
frexp was not used either.

Rich

  parent reply	other threads:[~2024-04-12 19:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12  1:17 Peter Ammon
2024-04-12  2:34 ` Rich Felker
2024-04-12 19:57 ` Rich Felker [this message]
2024-04-12 23:33   ` Rich Felker
2024-04-13 16:00     ` Peter Ammon

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=20240412195728.GE4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=corydoras@ridiculousfish.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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