From: Morten Welinder <mwelinder@gmail.com>
To: musl@lists.openwall.com
Subject: Re: printf issues
Date: Fri, 4 Apr 2014 13:42:30 -0400 [thread overview]
Message-ID: <CANv4PN=LsCLdOmgUwx5JD=cCVj3+KWDj3c-KRexjLNY4xZShPw@mail.gmail.com> (raw)
In-Reply-To: <20140404150705.GN26358@brightrain.aerifal.cx>
> I _would_ like this code to be easily adaptable for use outside libc
> if somebody wants it
FYI, I have been doing just that for Gnumeric in a variant that always
rounds ties away from zero. Two changes would help with making
the code fit seamlessly into other environments.
1. Make "i" in fmt_fp unsigned. It's used in connection with
unsigned values only.
2. Make "char *s" used to hold "NAN" etc. "const char *s".
Neither of these should make any difference in what the function
actually does.
I have run tens of millions random numbers through this function
looking for differences between it and glibc. The extra 0s from "%g"
is the only problem observed.
It looks like the LDBL_EPSILON version could be used in
roundl.c
modfl.c
ceill.c
floorl.c
in the definition of TOINT instead of enumerating choices for
LDBL_MANT_DIG. It's basically the same thing going on
there.
While I was looking for that, I noticed that this modfl fallback looks
problematic. Even if long double and double are the same thing
under the hood, I don't think you can cast pointers like that and
assume it works. It needs a temporary.
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double modfl(long double x, long double *iptr)
{
return modf(x, (double *)iptr);
}
Morten
On Fri, Apr 4, 2014 at 11:07 AM, Rich Felker <dalias@aerifal.cx> wrote:
> On Fri, Apr 04, 2014 at 10:35:00AM -0400, Morten Welinder wrote:
>> > before you can mock libc code you need to educate yourself
>>
>> I did and that's why I called the code "cute", not "wrong". But if you read
>> the porting documentation
>>
>> http://brightrain.aerifal.cx/~niklata/PORTING
>> http://www.openwall.com/lists/musl/2012/07/08/1
>>
>> you will notice that nowhere does it warn that defining LDBL_MANT_DIG
>> as anything but a base-10 constant may cause printf-rounding to fail.
>
> Good point.
>
>> > Do you have any ideas for a clean way to avoid this
>> > assumption without having to compute the value at runtime?
>>
>> I don't know if ldexpl will get constant folded by the compiler, but if not,
>> I think (2.0L/LDBL_EPSILON) ought to work as a replacement. It's not
>> as likely to get prices at the obfuscated C contents, though.
>
> Thanks, I think that's exactly the right solution. FWIW, I _would_
> like this code to be easily adaptable for use outside libc if somebody
> wants it, so eliminating implementation-internal assumptions like this
> is nice.
>
> Rich
next prev parent reply other threads:[~2014-04-04 17:42 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-04 13:32 Morten Welinder
2014-04-04 14:12 ` Rich Felker
2014-04-04 14:15 ` Szabolcs Nagy
2014-04-04 14:35 ` Morten Welinder
2014-04-04 14:56 ` Szabolcs Nagy
2014-04-04 15:07 ` Rich Felker
2014-04-04 17:42 ` Morten Welinder [this message]
2014-04-04 18:54 ` Szabolcs Nagy
2014-04-04 20:01 ` Morten Welinder
2014-04-04 20:22 ` Morten Welinder
2014-04-04 21:08 ` Rich Felker
2014-04-04 22:50 ` Morten Welinder
2014-04-05 0:01 ` Morten Welinder
2014-04-05 1:41 ` Rich Felker
2014-04-07 7:29 ` Rich Felker
2014-04-07 13:40 ` Morten Welinder
2014-04-07 14:13 ` Morten Welinder
2014-04-07 15:36 ` Szabolcs Nagy
2014-04-07 18:04 ` Rich Felker
2014-04-04 20:54 ` Szabolcs Nagy
2014-04-04 21:02 ` Rich Felker
2014-04-05 2:08 ` Morten Welinder
2014-04-05 2:50 ` Rich Felker
2014-04-06 23:07 ` Szabolcs Nagy
2014-04-04 21:00 ` Rich Felker
2014-04-04 21:10 ` Szabolcs Nagy
2014-04-04 20:58 ` Rich Felker
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='CANv4PN=LsCLdOmgUwx5JD=cCVj3+KWDj3c-KRexjLNY4xZShPw@mail.gmail.com' \
--to=mwelinder@gmail.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).