Re: gcc 11.1.0: printf("%.43f\n", 0x1.52f8a8e32e982p-140): printed value is incorrectly rounded

Keith Packard <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Brian Inglis <[email protected]> writes:

> Keith,
>
> I believe the implementation uses tables: that could be an issue in the 
> embedded world; can you comment on the table space required for 32, 64, 
> 128 bits?

I don't have a long double implementation of the ryu code; 128 bit
doubles would require 256 bit arithmetic (add/mul, fortunately no
divide), and a bunch of analysis to generate the table values. The
sample code on github only provides 32- and 64- bit
implementations. Picolibc currently has an imprecise printf
implementation for long double that works for Intel (80 bit) Risc-V
(IEEE 128 bit) and Power PC ('double double' 128-bit).

The total size of printf using the Ryu code is substantially smaller
than that required by the current newlib bits as it doesn't drag in the
arbitrary precision functions. The tables are 830 bytes.

I did a presentation in September at the Embedded Linux Conference where
I showed some complete binary numbers that involved printf

        #include <stdio.h>

        void main(void)
        {
                printf("%g\n", 355.0/113.0);
        }

On Cortex M3 hardware (an STM32L152 discovery board):

                             ROM     RAM
    Picolibc 64-bit         6872      24
    Picolibc 32-bit         5360      24
    Newlib 64-bit          15584    1200+1084

The newlib number for RAM includes both static and sbrk amounts;
picolibc doesn't call sbrk for this example. These are complete
examples, including semihosting code to display the numbers using
openocd on the target hardware.

-- 
-keith
signature.asc (application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAmGEnP4ACgkQ2yIaaQAA
ABFZIxAAqm8A9VOCVdXb8H2FZDTbErY938rD7XHfSyWbjzbX/AFwTUxcpycOKDvU
jYE37e4sMggLBiMoMJQbEktYR+8A1nwVAS0ryGnZt9bp1LYVt3HeRZfuq/a1hlyh
R9zuVegIUUJTu+jgUIIxKDPpF5HOADyve5njToFL3SYooJ5LxTQlv9wF8Vkjlnaq
VvRholLfC5an/K6KV2sQP6UDg5QgyEd6FVbqvTYTMAr3XnlIRNEgefWGDDs3TR/p
fT4R92Y+k3GAqBWw6On6QMef2GcqpDN1vJoHylcwyEaF5pBs/gxqwhfbsHsVPyWg
FCZ2/ZJ1YMeP8+2TXVBNUsuXZaBokx4xXJ1ay5UBh6nFi1wEjawpXVI2GG5uI2Kr
UT+eRDCPlg49HNXdlHFIgyQdsaAEqCAxCGO4NOqEa03BVUiORvQhnsJU5IcJrHod
c3UWV9JyPE5VzwfKgw6sjzlBpM5uKoO3P1xQ/31GykLtfBQeZhhoTGzwtNfJX1Um
AK/SA1TvKr1U9357tp0iMB9aSNGkc8n7L8dXEHvQmHb1A0Nw8WA6nkmEkpfv6WV2
PMJ6hsmh0EnflGxslFpVF3jXlAkXsM+GL9DggUcblvH7wqYLPig1JtKyi8EvRryd
FJt72Pex9Z19pdRRpIy8BI3XucqRgP+58661bVaooNjKZj5bNIk=
=63pw
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.