From owner-freebsd-mips@freebsd.org Tue Nov 14 15:58:06 2017 Return-Path: Delivered-To: freebsd-mips@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D0305DD49A7 for ; Tue, 14 Nov 2017 15:58:06 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AAB146368C for ; Tue, 14 Nov 2017 15:58:06 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by mail.baldwin.cx (Postfix) with ESMTPSA id B7FCB10A8BC; Tue, 14 Nov 2017 10:58:05 -0500 (EST) From: John Baldwin To: freebsd-mips@freebsd.org Subject: Re: fabs(-0.0) returns -0.0 Date: Mon, 13 Nov 2017 17:43:51 -0800 Message-ID: <2687660.XtxPXlZaqn@ralph.baldwin.cx> User-Agent: KMail/4.14.10 (FreeBSD/11.1-STABLE; KDE/4.14.30; amd64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail.baldwin.cx); Tue, 14 Nov 2017 10:58:05 -0500 (EST) X-Virus-Scanned: clamav-milter 0.99.2 at mail.baldwin.cx X-Virus-Status: Clean X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Nov 2017 15:58:06 -0000 On Monday, November 13, 2017 10:52:10 PM Khilan Gudka wrote: > Hi, > > The implementation of fabs(3) for MIPS (at least) appears to not be giving > the right answer for when -0 is passed, as it returns -0 instead of +0. The > implementation of fabs is: > > double fabs(double x) { > if (x < 0) > return -x; > return x; > } > > The if-test fails for -0 and thus it is returned. Is this a known issue? A > simple fix would be to return x+0.0 instead of just x. > > The implication of this is that other functions which rely on fabs, such as > hypot, also return -0. For example, hypot(-0.0, 0.0) returns -0 instead of > +0. The C version of fabs() for 32-bit arm has the same misimplementation btw. All other architectures implement fabs in assembly in libc. -- John Baldwin