From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id EAC3E22223 for ; Fri, 12 Apr 2024 03:17:56 +0200 (CEST) Received: (qmail 15973 invoked by uid 550); 12 Apr 2024 01:17:48 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 15941 invoked from network); 12 Apr 2024 01:17:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= ridiculousfish.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to; s=fm1; t= 1712884660; x=1712971060; bh=p2JZ6+aZJew+G6odABKU/0CDhnUpO9L2irg yGeu8owo=; b=KQ89Mm8/M63vlY3eDsfxLRu1uzi84l6kSMRjBK9c1OdPNaB/R2y LHIb9ecE+7ibbTyQJwJODtPxs9yBNJiXMnoX6eXZRNlMk9rmJ10PdDlov2SKnTfQ sRDl9dj39dup/t+sRh749pbK17fvhRQyzBrQ4cspap/En7ISh3rYXoLUuYcwXVYt d/z4rNYPj3ZDAVsJacq1pXemA6it9j+9McDdBPXyiPBwKu/n9afs5lVZFn+TRB/o 7AOSkc3f5hlkVtuRp/qFQU+bGYi6aSfQahhfmvMna/1jf0BDcOpZ9ra8tko5OTFw gUVFWIAV0tQO1df+TAF676Ox/E3J8CPe8fA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712884660; x=1712971060; bh=p2JZ6+aZJew+G6odABKU/0CDhnUp O9L2irgyGeu8owo=; b=tjXm4epKAowYp2oW2dq+F7FzPF46MFcUwI8LomaBoQt9 jlR48RX2YHLTn24W8lm4DnmwsdE/gQdzLQIk/VyOvNwNJ/FW7MVCOWcFYv0VZvOj WE0uOP1swHoFK8Mja+7zexXE8Zmo7u0o6YR5Nn8Jk+4Cv+L8bsITk4gp3nvvMd17 t4E/+XE/2C6G/ZjjAxUEimX5cSac0OdslKgvMCwfi3/zTqjUJQRvx5EUJNRV9sVe zm8t/DJ79IWevs3hwuj+T95XW+e98KFfLy/Kr1xsGlqpEq1pYqpyDQKNa0usHFr4 sZpGbBjR91RhZpAYA2f+L7Icw8mQxsLJWIrr9Tadxw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeitddguddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhtgfgggfukfffvffosehtqhhmtd hhtddvnecuhfhrohhmpefrvghtvghrucetmhhmohhnuceotghorhihughorhgrshesrhhi ughitghulhhouhhsfhhishhhrdgtohhmqeenucggtffrrghtthgvrhhnpefgvddvleevje eigefhfeehheelgeffjeefhffhuedvteeilefgtdfgleefvefhveenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegtohhrhiguohhrrghssehrih guihgtuhhlohhushhfihhshhdrtghomh X-ME-Proxy: Feedback-ID: i0ec14495:Fastmail From: Peter Ammon Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.400.31\)) Message-Id: Date: Thu, 11 Apr 2024 18:17:25 -0700 To: musl@lists.openwall.com X-Mailer: Apple Mail (2.3774.400.31) Subject: [musl] [PATCH] Fix printf hex float formatting with precision printf hex formatting with precision may emit excess digits on targets = where long double is an alias of double. For example, on ARMv7, the = expression `printf("%.12a", M_PI)` outputs 13 digits past the decimal, = instead of 12. I believe the cause is a bogus rounding calculation in fmt_fp: if (p<0 || p>=3DLDBL_MANT_DIG/4-1) re=3D0; else re=3DLDBL_MANT_DIG/4-1-p; if (re) { round *=3D 1<<(LDBL_MANT_DIG%4); while (re--) round*=3D16; ... I wasn't able to justify the calculation of `re`; I think it suffers = from trying to round in terms of number of hex digits, which is tricky = because the number of fractional mantissa bits may not be a multiple of = 4. I propose to fix it by working in bits instead of hex digits, as = follows: if (p>=3D0 && p<(LDBL_MANT_DIG-1+3)/4) { int re =3D LDBL_MANT_DIG-1-(p*4); long double round =3D 1ULL<=3DLDBL_MANT_DIG/4-1) re=3D0; - else re=3DLDBL_MANT_DIG/4-1-p; - - if (re) { - round *=3D 1<<(LDBL_MANT_DIG%4); - while (re--) round*=3D16; + if (p>=3D0 && p<(LDBL_MANT_DIG-1+3)/4) { + int re =3D LDBL_MANT_DIG-1-(p*4); + long double round =3D 1ULL<