From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4787 Path: news.gmane.org!not-for-mail From: Morten Welinder Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf issues Date: Fri, 4 Apr 2014 16:01:08 -0400 Message-ID: References: <20140404141515.GD3034@port70.net> <20140404150705.GN26358@brightrain.aerifal.cx> <20140404185413.GH3034@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1396641690 6131 80.91.229.3 (4 Apr 2014 20:01:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2014 20:01:30 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4791-gllmg-musl=m.gmane.org@lists.openwall.com Fri Apr 04 22:01:25 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WWAIm-00022C-TH for gllmg-musl@plane.gmane.org; Fri, 04 Apr 2014 22:01:24 +0200 Original-Received: (qmail 21873 invoked by uid 550); 4 Apr 2014 20:01:24 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 21864 invoked from network); 4 Apr 2014 20:01:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/c0r+casGFsE0x0ld2dspdS/mrKcnb8HtKqhvubmiP4=; b=SpRjq7PktcjXx3lZqS0ZhYGjzIMwkvCvt35MIQz3E7KbsVW3Jmkbux1/DBzJqVKlDw J3AB+yj9bPvDFSVJLcMeGZeMNushcK14AEeScZhq+dlyagkYJiZpP2ngM5M/QgidASxy rChQX5N44sLCvc5BFM048B0uIlA7QPDwA1uE+poX301NdON8ceNGL0pfRKlO+5S1p9E+ eDnfgLfAJxKWdGa/cf4Avfis4qi5mXez+btNaLaif5Xw7cevw6J7glQvJjtNJcxH1O00 nCsSJwr+4aDrP+fhP/2pIi3+OlAwDStfbBxFoGdBhFGPwkz8nTByf/Ln8ZXSnxAmm99s 4yBw== X-Received: by 10.180.101.40 with SMTP id fd8mr7056647wib.1.1396641668233; Fri, 04 Apr 2014 13:01:08 -0700 (PDT) In-Reply-To: <20140404185413.GH3034@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:4787 Archived-At: In fmt_fmt, the rounding decision is done using this test: /* Decide whether to round by probing round+small */ if (round+small != round) { ... Why is this done with long double? The reason I ask is that the Valgrind situation improves a lot if this is done with doubles. (Valgrind situation: Valgrind emulates long doubles, poorly, by using simple doubles. See, for example, https://bugs.kde.org/show_bug.cgi?id=164298) Morten On Fri, Apr 4, 2014 at 2:54 PM, Szabolcs Nagy wrote: > * Morten Welinder [2014-04-04 13:42:30 -0400]: >> 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 > > yes, that would be a bit nicer > (although other long double formats won't be supported anytime soon) > > (note that in the future these implementations may need to change > the current versions raise inexact flag if result!=input, but the > next version of the floating-point extension standard for c > will require suppressing inexact, which i dont know how to do > with simple arithmetics efficiently without accessing the fenv..) > >> 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); >> } > > yes, this is an aliasing violation, nice catch > > the original idea was to allow tail call opt for these wrappers, > so they are a single branch instruction, we should fix it but > i think we can rely on that the ptr representations are the same: > > long double modfl(long double x, long double *iptr) > { > union {long double *ld; double *d;} u = {iptr}; > return modf(x, u.d); > }