From: Steven Abner <pheonix.sja@att.net>
To: Newlib <newlib@sourceware.org>
Subject: Re: gcc 11.1.0: printf("%.43f\n", 0x1.52f8a8e32e982p-140): printed value is incorrectly rounded
Date: Fri, 05 Nov 2021 12:00:49 -0400 [thread overview]
Message-ID: <1636128049.25340.0@smtp.mail.att.net> (raw)
In-Reply-To: <87r1bvtipt.fsf@keithp.com>
[-- Attachment #1: Type: text/plain, Size: 3030 bytes --]
If you are bold enough to try something different here is some code
to examine. I could butcher up something to create full implementation
outside my code. Testing showed faster than gdtoa. Low precision
routines around 0 exponent show near tie. Added code to show how I
have connected to my printf:
case 'a': case 'e': case 'f': case 'g':
case 'A': case 'E': case 'F': case 'G':
/* gcc doesn't permit floats, it converts to doubles */
{
unsigned char *(*toStr)(uint32_t [5], unsigned char **,
int, int, int,
unsigned);
uint32_t w160[5];
uint32_t dp; /* 4 byte decimal point param */
int32_t sch;
__decimalLoad((unsigned char*)&dp, params);
if ((ch | 0x20) == 'a') ch -= 'A', toStr = realtohex;
else ch -= 'E', toStr = realtostr;
sch = format[-1];
/* force 128bit long double into quad parsing */
if (sch == 'q') {
#if (__LDBL_MANT_DIG__ != 64)
quad_parse:
#endif
sch = (('q' << 8) | ch);
qtow(((vPtr == NULL) ? va_arg(arg, octle) : *(octle *)vPtr),
w160);
} else if (sch == 'L') {
#if (__LDBL_MANT_DIG__ != 64)
goto quad_parse;
#endif
sch = (('L' << 8) | ch);
ldtow(((vPtr == NULL) ? va_arg(arg, long double) : *(long
double *)vPtr), w160);
} else {
sch = (('l' << 8) | ch);
dtow(((vPtr == NULL) ? va_arg(arg, double) : *(double
*)vPtr), w160);
}
arg_flags |= (strBuf != buffer) << 7;
strPtr = toStr(w160, &strBuf, sch, arg_prec, (int)arg_flags,
dp);
}
if (strPtr == NULL) goto error;
val_ul = (n = (int)(strPtr - strBuf));
strPtr = strBuf;
arg_prec = 0;
arg_flags &= ~ALT_PREFIX;
if ((arg_flags & GRP_PREFIX) != 0)
strPtr = __localizeReal(strPtr, &n), val_ul = n;
goto L300;
This is part of my sys/types so above 'octle' doesn't look so strange:
typedef union {
#if __SIZEOF_INT128__ == 16
uint128_t uo;
#endif
#ifdef __BIG_ENDIAN__
struct { uint64_t ull1, ull0; } ulls;
struct { uint32_t ul3, ul2, ul1, ul0; } uls;
struct { uint16_t us7, us6, us5, us4, us3, us2, us1, us0; } uss;
#else /* __LITTLE_ENDIAN__ */
struct { uint64_t ull0, ull1; } ulls;
struct { uint32_t ul0, ul1, ul2, ul3; } uls;
struct { uint16_t us0, us1, us2, us3, us4, us5, us6, us7; } uss;
#endif
} octle;
And from sysdep.h for attached ldtostr:
/* endian break down of uint64_t */
#ifdef __BIG_ENDIAN__
typedef struct { uint16_t w3; uint16_t w2; uint16_t w1; uint16_t w0;
} _ull_ws;
typedef struct { uint32_t hi; uint32_t lo; } _ull_ls;
#elif defined (__LITTLE_ENDIAN__)
typedef struct { uint16_t w0; uint16_t w1; uint16_t w2; uint16_t w3;
} _ull_ws;
typedef struct { uint32_t lo; uint32_t hi; } _ull_ls;
#else
#error: undefined endianness
#endif
typedef union { uint64_t ull; _ull_ls uls; _ull_ws uss; } _ull_t;
Steve
[-- Attachment #2: ldtostr.c.zip --]
[-- Type: application/zip, Size: 19500 bytes --]
next prev parent reply other threads:[~2021-11-05 16:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAL9Mx1uMOz2wfqbMpD_xfA=D9JkpFzVz6AR_DKHK34AvrGOP6w@mail.gmail.com>
2021-11-03 21:26 ` Fwd: " Pavel M
2021-11-04 12:24 ` Corinna Vinschen
2021-11-04 16:48 ` Keith Packard
2021-11-04 17:27 ` Dave Nadler
2021-11-04 17:58 ` Keith Packard
2021-11-04 21:28 ` Brian Inglis
2021-11-05 2:54 ` Keith Packard
2021-11-05 16:00 ` Steven Abner [this message]
2021-11-06 12:06 ` Steven Abner
2021-11-06 23:25 ` Steven Abner
2021-11-08 9:57 ` Corinna Vinschen
2021-11-04 20:57 ` Corinna Vinschen
2021-11-28 7:43 ` Takashi Yano
2021-11-28 12:38 ` Takashi Yano
2021-11-28 13:16 ` Takashi Yano
2021-11-29 10:56 ` Takashi Yano
2021-11-29 14:24 ` Takashi Yano
2021-11-29 15:55 ` Corinna Vinschen
2021-11-30 10:51 ` Takashi Yano
2021-11-30 15:09 ` Corinna Vinschen
2021-11-30 20:38 ` Takashi Yano
2021-11-30 21:17 ` Takashi Yano
2021-12-06 9:53 ` Corinna Vinschen
2021-12-06 10:26 ` Takashi Yano
2021-12-01 12:05 ` Takashi Yano
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=1636128049.25340.0@smtp.mail.att.net \
--to=pheonix.sja@att.net \
--cc=newlib@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).