From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6317 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains Date: Tue, 14 Oct 2014 10:06:35 +0200 Message-ID: <20141014080634.GC4874@port70.net> References: <20141014024238.GL32028@brightrain.aerifal.cx> <20141014030325.GM32028@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1413287118 29383 80.91.229.3 (14 Oct 2014 11:45:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 14 Oct 2014 11:45:18 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6330-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 14 13:45:06 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 1Xe0XJ-0006qz-UD for gllmg-musl@plane.gmane.org; Tue, 14 Oct 2014 13:45:06 +0200 Original-Received: (qmail 22142 invoked by uid 550); 14 Oct 2014 11:46:13 -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 22132 invoked from network); 14 Oct 2014 11:46:12 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:6317 Archived-At: * bobodog <8192542@qq.com> [2014-10-14 14:26:01 +0800]: > diff --git a/src/math/ceil.c b/src/math/ceil.c > index 22dc224..8634145 100644 > --- a/src/math/ceil.c > +++ b/src/math/ceil.c > @@ -4,15 +4,16 @@ double ceil(double x) > { > union {double f; uint64_t i;} u = {x}; > int e = u.i >> 52 & 0x7ff; > + uint64_t n = 0x1p52; > double_t y; > > if (e >= 0x3ff+52 || x == 0) > return x; > /* y = int(x) - x, where int(x) is an integer neighbor of x */ > if (u.i >> 63) > - y = (double)(x - 0x1p52) + 0x1p52 - x; > + y = (double)(x - n) + n - x; > else > - y = (double)(x + 0x1p52) - 0x1p52 - x; > + y = (double)(x + n) - n - x; > /* special case because of non-nearest rounding modes */ > if (e <= 0x3ff-1) { > FORCE_EVAL(y);??? > > To solve this problem, must define a variate: uint64_t n = 0x1p52; > using n to instead of 0x1p52, then all result are correctly.??? > this is not necessary (and possibly makes things slower) in c99 the difference must not be observable, your compiler is broken if it is > > The compile flags: > MCFLAGS := -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -mfpu=neon -ftree-vectorize -ffast-math -mfloat-abi=softfp??? > never ever -ffast-math if you use that flag all bets are off > > I belive, when using this flags, the bug will happen. any one tell me how to solve it. we need optimizing flags to compile musl libc.??? > when compiling libc dont use that flag otherwise you can use it but i strongly suggest not to, unless you are fully aware of the consequences